app.controller("z-attendance-c", [ '$scope','$rootScope','$z-http','$sce','z-attendance-s','z-edit-menu-s','z-role-s','$filter','z-request-s','z-restVacation-s','z-requestApproval-s',
		function($scope,$rootScope,$zhttp,$sce,Service,MenuService,RoleService,$filter,$request,RestVacationService,RequestApprovalService) {
		$scope.viewModel = {};
		$scope.editModel = {};
		$scope.editModel.retroactive = {};
		$scope.viewModel.perPage = "10";
		$scope.viewModel.rowCount = "1";	
		//下拉多选框长度
		$scope.multiSelectMaxHeight=300;
		var now = new Date();                    //当前日期     
		var nowMonth = now.getMonth();           //当前月     
		var nowYear=$filter('date')(now,'yyyy'); //当前年
		//获取当月开始日期
		var monthStartDate = $filter("date")(new Date(nowYear, nowMonth, 1), "yyyy/MM/dd");
		//获取当前日期
        var dayEndDate= $filter("date")(now, "yyyy/MM/dd");
		$scope.viewModel.attendanceStratDate=new Date(monthStartDate);    //起止日期
		$scope.viewModel.attendanceEndDate=new Date(dayEndDate);	  	  //终止日期
		$scope.viewModel.attendanceStateList=[];
		//异常信息定义
		$scope.viewModel.shouldAttendanceTime="";	//应出勤工时
		$scope.viewModel.attendanceTime="";	//出勤工时
		$scope.viewModel.leaveNumber="";	//请假次数
		$scope.viewModel.leaveDay="";	//请假天数
		$scope.viewModel.leaveTime="";	//请假时间
		$scope.viewModel.lateNumber="";	//迟到次数
		$scope.viewModel.lateHours="";	//迟到时间
		$scope.viewModel.leaveEarlyNumber="";	//早退次数
		$scope.viewModel.leaveEarlyHours="";	//早退时间
		$scope.viewModel.retroactiveNumber="";	//补签次数
		$scope.viewModel.absenteeismNumber="";	//旷工次数
		$scope.viewModel.overTime="";
		$scope.viewModel.descSort=true;
		$scope.viewModel.dayType=false;    //控制补签天数
		$scope.viewBatchProductAssignmentModel = {};
		
		//日期控件
		$scope.viewModel.dateOptions = {
				formatYear: 'yy',
			    startingDay: 1,
			    showWeeks:false
		};
		
		//日期控件
		$scope.viewModel.format = "yyyy/MM/dd";
		//日期启动开关
		$scope.viewModel.startDateOpened = false;
		$scope.viewModel.endDateOpened = false;
		$scope.viewModel.attendanceDateOpened = false;
		$scope.viewModel.attendanceDateOpened2 = false;
		
		
		//查询页面名称
		MenuService.getMenuByUrl({url:'attendance'},
		function(data){	
			$scope.viewModel.menuList=data;
		},function(error) {});
		
		$scope.viewModel.attendanceDateOpen= function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$("#rAStartTimehsdate").hide();
			$("#rAEndTimehsdate").hide();
			$scope.viewModel.attendanceDateOpened = !$scope.viewModel.attendanceDateOpened;
		};
		
		//起止日期选择
		$scope.viewModel.startDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.startDateOpened = !$scope.viewModel.startDateOpened;
		};
		
		//起止日期选择
		$scope.viewModel.endDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$scope.viewModel.endDateOpened = !$scope.viewModel.endDateOpened;
		};
		
		//背景颜色
		$scope.viewModel.trStyle=function(attendance){
			if(attendance.attendanceStateName=="旷工"
					|| attendance.attendanceStateName=="迟到"
						|| attendance.attendanceStateName=="早退"){
				var dataStyle={
						 "background-color":"rgba(253, 245, 195, 0.66)"
				};
				return dataStyle;
			}
		};
		
		$scope.viewModel.startTimeClick=function(){
			$("#rAStartTimehsdate").hide();
			$("#rAEndTimehsdate").hide();
			if($scope.viewModel.attendanceDateOpened){
				$scope.viewModel.attendanceDateOpened=false;
			}
		};
		
		$scope.viewModel.endTimeClick=function(){
			$("#rAStartTimehsdate").hide();
			$("#rAEndTimehsdate").hide();
			if($scope.viewModel.attendanceDateOpened){
				$scope.viewModel.attendanceDateOpened=false;
			}
		};
		
		// 将分钟数量转换为小时和分钟字符串
		$scope.viewModel.toHourMinute=function(minutes){
			if(minutes==null){
				return "";
			}
			return (Math.floor(minutes/60).toFixed(0) + "小时" + Math.floor(minutes%60).toFixed(0) + "分钟" );
		};

		//加载考勤状态数据
		$scope.viewModel.bindSelectData = function(){
			Service.getDictionaryListBydicCls({
				dicCls:"1"
			},
			function(data){
				var site = [];  
		        $.each(data, function(index, values) {  
		            site.push({  
		                label : values.dicName,  
		                value : values.dicCd  
		            });  
		        });  
		        $('#adlAttendanceState').multiselect('dataprovider',site);
			},function(error) {
						
			});
			//考勤状态
			$('#adlAttendanceState').multiselect({
				includeSelectAllOption: true,
				enableFiltering: true,
				delimiterText: '; ',
	            maxHeight: $scope.multiSelectMaxHeight
	        });
            Service.getDictionaryListBydicCls({
				dicCls:"5"
			},
			function(data){
				$scope.viewModel.requestTypeData=data;
			},function(error) {
			});

        };
		$scope.viewModel.bindSelectData();
		
		$scope.viewModel.bindRoleData = function(){
			$scope.viewModel.isLoading=true;
			//获取基本信息
			RoleService.getRoleListByEmployeeId({},
			function(data){
				$scope.viewModel.roleList = data;
				$scope.viewModel.isLoading=false;
			},function(error) {
				$scope.viewModel.isLoading=false;
			});
		};
		$scope.viewModel.bindRoleData();

		$scope.viewModel.dirty=function(){
			//验证不能为空
			$scope.editForm.aStartTime.$dirty=false;
			$scope.editForm.aEndTime.$dirty=false;
		};
		$scope.viewModel.retractAttednance = function(attendance,type){
			$rootScope.alertConfirm("确定撤回补签吗？",function() {
				$scope.viewModel.isLoading = true;
				Service.retractAttednance({
					attendanceId:attendance.attendanceId,
					type:type,
				},
				function(data){	
					$scope.viewModel.unLoad();
					$scope.viewModel.bindData();
					$rootScope.alertInfo("撤回补签成功。");
					$scope.viewModel.isLoading = false;
				},function(error) {
					$rootScope.alertError(error.fault.message);
					$scope.viewModel.isLoading = false;
				});
			});
		};
		//补签
		$scope.viewModel.addUser = function(retroctive,type){
			$scope.editModel.title="("+retroctive.attendanceStateName+")申请补签";
			$scope.editModel.attendanceDate=$filter("date")(retroctive.attendanceDate, "yyyy/MM/dd");
			$scope.editModel.startTime=retroctive.originalStartTime;
			$scope.editModel.endTime=retroctive.originalEndTime;
			$scope.editModel.attendanceState=retroctive.attendanceStateName;
			$scope.editModel.type = type;
			
			$scope.editModel.retroactive={};
			$scope.editModel.retroactive.attendanceId=retroctive.attendanceId;
			$scope.editModel.retroactive.startTime="";
			$scope.editModel.retroactive.endTime="";
			$scope.viewModel.show=true;
			$scope.viewModel.dirty();
			//小时控件jquery-timepicker
			$('#aStartTime').jHsDate({
				format:'hh:mm',
				callBack: function () {
						$scope.editForm.aStartTime.$valid=true;
						$scope.editForm.aStartTime.$invalid=false;
						$scope.editModel.retroactive.startTime=$('#aStartTime').val();
				}	
			});
			$('#aEndTime').jHsDate({
				format:'hh:mm',
				callBack: function () {
						$scope.editForm.aEndTime.$valid=true;
						$scope.editForm.aEndTime.$invalid=false;
						$scope.editModel.retroactive.endTime=$('#aEndTime').val();
				}	
			});
			if(type == 0){
				$scope.editModel.retroactive.description="";
			}else{
				$scope.editModel.retroactive.endTime="";
			}
			//判断考勤状态:
			if(retroctive.attendanceState=="2"){//2 迟到 
				$("#aEndTime").val(retroctive.endTime);
				$scope.editModel.retroactive.endTime=retroctive.endTime;
			}
			else if(retroctive.attendanceState=="3"){ //3 早退
				$("#aStartTime").val(retroctive.startTime);
				$scope.editModel.retroactive.startTime=retroctive.startTime;
			}
		};
		
	    $scope.viewModel.escapeRegExp=function(string){
	        var pattern=/^([0-9]|[0-1][0-9]|2[0-3]):(2[0-9]|[0-5][0-9])$/;
	        var flag = pattern.test(string);
	        return flag;
        };
        
		//验证
		$scope.viewModel.requiredForm= function() {
			var type=false;
			if (($scope.editModel.retroactive.startTime=="" || $scope.editModel.retroactive.startTime==null) && $scope.editModel.type == 0) {
				$rootScope.alertWarning("补签上班签到不能为空。");
		    	type=true;
		    }
			if (($scope.editModel.retroactive.endTime=="" || $scope.editModel.retroactive.endTime==null) && $scope.editModel.type == 1) {
				$rootScope.alertWarning("补签上班签到不能为空。");
		    	type=true;
		    }
			if(!$scope.viewModel.escapeRegExp($scope.editModel.retroactive.startTime)&&!$scope.viewModel.escapeRegExp($scope.editModel.retroactive.endTime)){
				type=true;
				$scope.editForm.aStartTime.$dirty=true;
				$scope.editForm.aEndTime.$dirty=true;
        	}
			
            if(type){
            	return true;
            }
//        	if($scope.editModel.retroactive.startTime==null){
//        		$rootScope.alertWarning("未选择补签上班签到时间！");
//        		return true;
//        	}else if($scope.editModel.retroactive.endTime==null){
//        		$rootScope.alertWarning("未选择补签末班签退时间！");
//        		return true;
//        	}
        	return false;
        };
        
        //关闭加载
		$scope.viewModel.unLoad=function(){
			$scope.viewModel.show=false;
		};
		
		//保存
		$scope.viewModel.save = function(){
			if($scope.viewModel.requiredForm()){
				return;
			}
			$scope.viewModel.isLoading = true;
			//保持前验证补签次数   
			Service.getIsAbleRetroactive($scope.editModel.retroactive,
				function(data){
					//保存
					$scope.viewModel.saveOn();
				},function(data) {
					$scope.viewModel.isLoading = false;
					if (angular.isArray(data['fault'])) {
						var faultMessage = [data['fault'][0]['message']].concat(data['fault'][0]['errorData']);
						$rootScope.alertWarning(faultMessage);
					} else {
						$rootScope.alertWarning(data['fault']['message']);
					}
				});
		};
				
		//加载数据
		$scope.viewModel.bindData = function(){
			$scope.viewModel.isLoading=true;
			//获取异常信息
			Service.getAttendanceData({
				attendanceDateStart:$scope.viewModel.attendanceStratDate,
				attendanceDateEnd:$scope.viewModel.attendanceEndDate,
				attendanceStateList:$scope.viewModel.attendanceStateList,
				
			},
			function(data){	
				$scope.viewModel.shouldAttendanceTime=data.shouldAttendanceTime;	//应出勤工时
				$scope.viewModel.attendanceTime=data.attendanceTime;	//出勤工时
				$scope.viewModel.leaveNumber=data.leaveNumber;	//请假次数
				$scope.viewModel.leaveDay=data.leaveDay;	//请假天数
				$scope.viewModel.leaveTime=data.leaveTime;	//请假时间
				$scope.viewModel.lateNumber=data.lateNumber;	//迟到次数
				$scope.viewModel.lateHours=data.lateHours;	//迟到时间
				$scope.viewModel.leaveEarlyNumber=data.leaveEarlyNumber;	//早退次数
				$scope.viewModel.leaveEarlyHours=data.leaveEarlyHours;	//早退时间
				$scope.viewModel.retroactiveNumber=data.retroactiveNumber;	//补签次数
				$scope.viewModel.absenteeismNumber=data.absenteeismNumber;	//旷工次数
				$scope.viewModel.overTime=data.overTime;
			},function(error) {

			});
			
			//获取基本信息
			Service.getAttendanceListById({
				descSort:$scope.viewModel.descSort,
				pageNo:$scope.viewModel.rowCount,
				pageCount:$scope.viewModel.perPage,
				attendanceDateStart:$scope.viewModel.attendanceStratDate,
				attendanceDateEnd:$scope.viewModel.attendanceEndDate,
				attendanceStateList:$scope.viewModel.attendanceStateList,
			},
			function(data){
				$scope.viewModel.dataList = data.attendanceBeanList;
				for(var i=0;i<$scope.viewModel.dataList.length;i++){
					$scope.viewModel.dataList[i].checkbox=false;
				}
				$scope.viewModel.totalData = data.pageTotal;
				$scope.viewModel.isLoading=false;
			},function(error) {
				$scope.viewModel.isLoading=false;
			});
		};
		
		//复选框是否选中
		$scope.viewModel.checkboxDisabled=function(attendance){
			var count=0;
			for(var i=0;i<$scope.viewModel.dataList.length;i++){
				if($scope.viewModel.dataList[i].checkbox){
					count++;
					break;
				}
			}
			if(count==0){
				return false;
			}
			else if(attendance.checkbox==false){
				return true;
			}
		};
		
		
		$scope.viewModel.bindData();
		
		//验证
		$scope.viewModel.validForm= function(isValid) {
            if (!isValid) {
                return;
            }else{
            	if($scope.viewModel.attendanceStratDate>$scope.viewModel.attendanceEndDate){
            		$scope.form.attendanceEndDate.$invalid=true;
            	}else{
            		$scope.viewModel.rowCount=1;
                	$scope.viewModel.bindData();
                	$scope.form.attendanceEndDate.$invalid=false;
            	}
            }
        };
        
        // 查看考勤状态过程
        $scope.viewModel.selectUser = function(attendance){
        	$scope.viewModel.isLoading=true;
			Service.getAttendanceRight({
				employeeNo:attendance.employeeNo,
				attendanceDate:attendance.attendanceDate
			},
			function(data){
				$scope.viewModel.attendanceRightBean = data;
				$scope.viewModel.isLoading=false;
				$scope.editModel.title="查看考勤状态详细信息";
				$scope.viewModel.loadSelect();
			},function(error) {
				$rootScope.alertError(error.fault.message);
				$scope.viewModel.isLoading=false;
			});
			$scope.viewBatchProductAssignmentModel.previous();
		};
		
		$scope.viewBatchProductAssignmentModel.isLoading=true;
		
		$scope.viewBatchProductAssignmentModel.viewIndex=0;
		
		//上一步
	    $scope.viewBatchProductAssignmentModel.previous=function(){
	        if($scope.viewBatchProductAssignmentModel.viewIndex==0){
	            return;
	        }
	        $scope.viewBatchProductAssignmentModel.viewIndex=$scope.viewBatchProductAssignmentModel.viewIndex-1;
		};

		/*  状态详情 */
		$scope.viewApprovalRecordModel = {};
	    //下一步
		$scope.viewBatchProductAssignmentModel.next=function(request){
			//获取基本信息
			RequestApprovalService.getApprovalRecordInfoById({
				requestId:request.requestId,
			},
			function(data){
				$scope.viewApprovalRecordModel.dataList = data;
			},function(error) {
				$rootScope.alertError(error.fault.message);
			});
	        if($scope.viewBatchProductAssignmentModel.viewIndex==1){
	            return;
	        }
	        $scope.viewBatchProductAssignmentModel.viewIndex=$scope.viewBatchProductAssignmentModel.viewIndex+1;
		};
		
		
		//加载
		$scope.viewModel.loadSelect=function(){
			$scope.viewModel.showSelect=true;
		};
		//关闭加载
		$scope.viewModel.unLoadSelect=function(){
			$scope.viewModel.showSelect=false;
		};
		$scope.viewApprovalRecordModel = {};
		//查看补签状态过程
		$scope.viewModel.selectUsers = function(attendance){
			Service.getApprovalRecordByAttendanceId({
				attendanceId:attendance.attendanceId,
			},
			function(data){
				$scope.viewApprovalRecordModel.dataList = data;
				$scope.viewModel.isLoading=false;
				$scope.editModel.title="查看补签状态过程";
				$scope.viewModel.loadSelects();
			},function(error) {
				$rootScope.alertError(error.fault.message);
				$scope.viewModel.isLoading=false;
			});
			
		};
		//加载
		$scope.viewModel.loadSelects=function(){
			$scope.viewModel.showSelects=true;
		};
		//关闭加载
		$scope.viewModel.unLoadSelects=function(){
			$scope.viewModel.showSelects=false;
		};
        //控制升序，降序
        $scope.viewModel.order=function(){
        	if($scope.viewModel.descSort){
        		$scope.viewModel.descSort=false;
        	}else{
        		$scope.viewModel.descSort=true;
        	}
        	if($scope.viewModel.attendanceStratDate>$scope.viewModel.attendanceEndDate){
        		$scope.form.attendanceEndDate.$invalid=true;
        	}else{
        		$scope.form.attendanceEndDate.$invalid=false;
        		$scope.viewModel.rowCount=1;
            	$scope.viewModel.bindData();
        	}
        };
        
        $scope.viewModel.selected=function(role){
        	if(role.isRole==1){
        		$scope.editModel.retroactive.roleId=role.roleId;
        		return true;
        	}
        	return false;
        };
        /** 补签 **/
        $scope.viewRetroactiveModel={};
        $scope.viewRetroactiveModel.show=false;
        
		$scope.editRetroactiveModel={};
		$scope.editRetroactiveModel.retroactive = {};
		$scope.editRetroactiveModel.retroactiveType=true;
		$scope.editRetroactiveModel.retroactiveValue="1";
		$scope.editRetroactiveModel.checkboxlength=0;
		$scope.editRetroactiveModel.type=0;
		$scope.editRetroactiveModel.dataMorningList=[];
		$scope.editRetroactiveModel.attendanceEndDate="";
		$scope.editRetroactiveModel.startTime =null;
        $scope.editRetroactiveModel.endTime =null;
		$scope.editRetroactiveModel.acrossCheckbox=false;
		$scope.editRetroactiveModel.dataMorningType=false;
		
		//控制日期框长度
		$scope.editRetroactiveModel.divClass=function(){
			var classStr="col-sm-8 col-md-6 form-input";
			if($scope.editRetroactiveModel.dataMorningType==false){
				classStr="col-sm-8 col-md-8 form-input";
			}
			return classStr;
		};
		
		$scope.editRetroactiveModel.acrossCheckboxClick=function(){
			$scope.editRetroactiveModel.retroactiveValue=1;
			if($scope.editRetroactiveModel.dataMorningList.length==0){
				$scope.viewRetroactiveModel.attendanceDateChange();
			}else{
				$scope.editRetroactiveModel.dataMorningList=[];
				var retroctive=null;
	        	//处理选择框
	        	for(var i=0;i<$scope.viewModel.dataList.length;i++){
	        		if($scope.viewModel.dataList[i].checkbox){
	        			retroctive=angular.copy($scope.viewModel.dataList[i]);
	        		}
	        	}
				if(retroctive!=null){
					$scope.editRetroactiveModel.startTime=retroctive.originalStartTime;
					$scope.editRetroactiveModel.endTime=retroctive.originalEndTime;
				}else{
					$scope.editRetroactiveModel.startTime =null;
			        $scope.editRetroactiveModel.endTime =null;
				}
			}
		};
		
		//点击
		$scope.editRetroactiveModel.startTimeClick=function(date){
			 $scope.editRetroactiveModel.startTime=date.morningTime;
		};
		
		$scope.editRetroactiveModel.endTimeClick=function(date){
			 $scope.editRetroactiveModel.endTime=date.morningTime;
		};
		
		//控制显示
		$scope.editRetroactiveModel.show=function(){
			if($scope.editRetroactiveModel.dataMorningList.length<=0){
				if($scope.editRetroactiveModel.retroactiveValue==1){
					return true;
				}
			}
			return false;
		};
		
		//控制显示
		$scope.editRetroactiveModel.hide=function(){
			if($scope.editRetroactiveModel.dataMorningList.length<=0){
				if($scope.editRetroactiveModel.retroactiveValue==2){
					return true;
				}
			}
			return false;
		};
		
		
        // 跨天补签结束日
		$scope.editRetroactiveModel.formatEndDate=function(date) {
			if ( date != null ) {
				var dateOut = new Date(date);
				dateOut.setDate(dateOut.getDate()+1);
				return dateOut;
			}
			return "";
		};
        //日期选择加载签到时间信息
        $scope.viewRetroactiveModel.attendanceDateChange=function(){
			$scope.editRetroactiveModel.retroactiveValue=1;
			var retroctive=null;
        	//处理选择框
        	for(var i=0;i<$scope.viewModel.dataList.length;i++){
        		if($scope.viewModel.dataList[i].checkbox){
        			retroctive=angular.copy($scope.viewModel.dataList[i]);
        		}
        	}
        	//获取基本信息
			Service.getCheckinoutMorningList({
				attendanceDate:$scope.editRetroactiveModel.retroactive.attendanceDate
			},
			function(data){
				$scope.editRetroactiveModel.dataMorningList = data;
				$scope.editRetroactiveModel.attendanceEndDate=$filter("date")($scope.editRetroactiveModel.formatEndDate($scope.editRetroactiveModel.retroactive.attendanceDate), "yyyy/MM/dd");
				if($scope.editRetroactiveModel.dataMorningList.length>0){
					//款天补签问题
					$scope.editRetroactiveModel.startTime=null;
					$scope.editRetroactiveModel.endTime=null;
					$scope.editRetroactiveModel.dataMorningType=true;
				}else{
					$scope.editRetroactiveModel.dataMorningType=false;
					//未选择请求补签接口
					if(retroctive==null){
						$scope.viewModel.isLoading=true;
						//获取基本信息
						Service.getAttendanceTimeByDate({
							attendanceDate:$scope.editRetroactiveModel.retroactive.attendanceDate
						},
						function(data){
							$scope.editRetroactiveModel.startTime=data.originalStartTime; //负值
							$scope.editRetroactiveModel.endTime=data.originalEndTime; //负值
							$scope.viewModel.isLoading=false;
						},function(error) {
							$scope.viewModel.isLoading=false;
						});
					}
				}
				$scope.editRetroactiveModel.acrossCheckbox=true;
				$scope.viewModel.isLoading=false;
			},function(error) {
				$scope.viewModel.isLoading=false;
			});
        };
		
        //加载一键补签页面
		$scope.viewRetroactiveModel.load=function(){
			var retroctive={};
			$scope.editRetroactiveModel.checkboxlength=0;
			$scope.editRetroactiveModel.type=0;
        	//处理选择框
        	for(var i=0;i<$scope.viewModel.dataList.length;i++){
        		if($scope.viewModel.dataList[i].checkbox){
        			retroctive=angular.copy($scope.viewModel.dataList[i]);
        			$scope.editRetroactiveModel.checkboxlength++;
        		}
        	}

        	if($scope.editRetroactiveModel.checkboxlength>1){
        		$rootScope.alertWarning("只能选择一条考勤信息操作！");
        		return;
        	}
        	
        
    		$scope.editRetroactiveModel.retroactive={};
			$scope.editRetroactiveModel.retroactive.roleId=null;
			$scope.editRetroactiveModel.retroactive.attendanceDate=null;
			$scope.editRetroactiveModel.retroactive.startTime=null;
			$scope.editRetroactiveModel.retroactive.endTime=null;
			$scope.editRetroactiveModel.retroactive.description=null;
			
			$scope.editRetroactiveModel.startTime =null;
            $scope.editRetroactiveModel.endTime =null;
			$scope.editRetroactiveModel.dataMorningList=[];
			$scope.editRetroactiveModel.dataMorningType=false;
			$scope.viewRetroactiveModel.show=true;
			
			//验证不能为空
			$scope.editRetroactiveForm.rAttendanceStratDate.$dirty=false;
			
			//是否勾选复选框
			if($scope.editRetroactiveModel.checkboxlength==1){
				$scope.editRetroactiveModel.retroactive.attendanceDate=retroctive.attendanceDate;
				$scope.editRetroactiveModel.attendanceState=retroctive.attendanceStateName;
				$scope.editRetroactiveModel.startTime=retroctive.originalStartTime;
				$scope.editRetroactiveModel.endTime=retroctive.originalEndTime;
				//调用接口，查看是否存在跨天补签情况
				$scope.viewRetroactiveModel.attendanceDateChange();
			}
			
			$scope.editRetroactiveForm.rAStartTime.$dirty=false;
			$scope.editRetroactiveForm.rAEndTime.$dirty=false;
			
			$('#rAStartTime').jHsDate({
				format:'hh:mm',
				callBack: function () {
					$scope.editRetroactiveForm.rAStartTime.$dirty=true;
					$scope.editRetroactiveForm.rAStartTime.$valid=true;
					$scope.editRetroactiveForm.rAStartTime.$invalid=false;
					$scope.editRetroactiveModel.retroactive.startTime=$('#rAStartTime').val();
				}	
			});
			$('#rAEndTime').jHsDate({
				format:'hh:mm',
				callBack: function () {
					$scope.editRetroactiveForm.rAEndTime.$dirty=true;
					$scope.editRetroactiveForm.rAEndTime.$valid=true;
					$scope.editRetroactiveForm.rAEndTime.$invalid=false;
					$scope.editRetroactiveModel.retroactive.endTime=$('#rAEndTime').val();
				}	
			});
		};
		
		$scope.viewRetroactiveModel.unLoad=function(){
			$scope.viewRetroactiveModel.show=false;
		};

        //补签天(一键补签)
        $scope.viewRetroactiveModel.addRetroactive=function(){
        	$scope.viewRetroactiveModel.load();
        };
        
        //验证
		$scope.viewRetroactiveModel.requiredForm= function() {
			if($scope.editRetroactiveModel.retroactive.attendanceDate==null){
				$scope.editRetroactiveForm.rAttendanceStratDate.$invalid=true;
        		$rootScope.alertWarning("签到日期请选择。");
        		return true;
        	}else{
        		$scope.editRetroactiveForm.rAttendanceStratDate.$invalid=false;
        	}
			if($scope.editRetroactiveModel.retroactiveValue==1){
				if(!$scope.editRetroactiveForm.rAStartTime.$valid){
					if(!$scope.editRetroactiveForm.rAStartTime.$dirty){
		        		$scope.editRetroactiveForm.rAStartTime.$dirty=true;
		        	}
					return true;
				}else{
					if(!$scope.viewModel.escapeRegExp($scope.editRetroactiveModel.retroactive.startTime)){
						$scope.editRetroactiveForm.rAStartTime.$invalid=true;
						return true;
		        	}
					$scope.editRetroactiveForm.rAStartTime.$invalid=false;
				}	
			}else if($scope.editRetroactiveModel.retroactiveValue==2){
				if(!$scope.editRetroactiveForm.rAEndTime.$valid){
					if(!$scope.editRetroactiveForm.rAEndTime.$dirty){
		        		$scope.editRetroactiveForm.rAEndTime.$dirty=true;
		        	}
					return true;
				}else{
					if(!$scope.viewModel.escapeRegExp($scope.editRetroactiveModel.retroactive.endTime)){
						$scope.editRetroactiveForm.rAEndTime.$invalid=true;
						return true;
					}
					$scope.editRetroactiveForm.rAEndTime.$invalid=false;
				}	
			}
        	return false;
        };
        
        // 跨天补签验证
		$scope.editRetroactiveModel.requiredAcrossForm = function() {
			if ($scope.editRetroactiveModel.startTime == null && $scope.editRetroactiveModel.endTime == null) {
                $rootScope.alertWarning("请选择一条补签时间。");
                return true;
			}
//            if ($scope.editRetroactiveModel.endTime == null ) {
//                $rootScope.alertWarning("上班签到时间请选择。");
//                return true;
//            }
			return false;
		};
		
        //保存补签
        $scope.viewRetroactiveModel.save=function(){
        	if($scope.editRetroactiveModel.dataMorningList.length==0){
        		if($scope.viewRetroactiveModel.requiredForm()){
    				return;
    			}
    			var retroctive=null;
            	//处理选择框
            	for(var i=0;i<$scope.viewModel.dataList.length;i++){
            		if($scope.viewModel.dataList[i].checkbox){
            			retroctive=angular.copy($scope.viewModel.dataList[i]);
            			break;
            		}
            	}

    			$scope.viewModel.isLoading = true;
    			//保持前验证补签次数
    			Service.getIsAbleRetroactive($scope.editRetroactiveModel.retroactive,
    				function(data){
    					if(retroctive==null){
    						//保存
        					$scope.viewModel.saveOnce();
    					}else{
    						$scope.editRetroactiveModel.retroactive.attendanceId=retroctive.attendanceId;
    						//保存
        					$scope.viewModel.saveOn();
    					}
    				},function(data) {
    					$scope.viewModel.isLoading = false;
    					if (angular.isArray(data['fault'])) {
    						var faultMessage = [data['fault'][0]['message']].concat(data['fault'][0]['errorData']);
    						$rootScope.alertWarning(faultMessage);
    					} else {
    						$rootScope.alertWarning(data['fault']['message']);
    					}
    				});
        	}else{
        		 if($scope.editRetroactiveModel.requiredAcrossForm()){
    				return;
    			 }
        		 $scope.viewModel.isLoading = true;
        		 
        		 $scope.editRetroactiveModel.retroactive.startTime=$scope.editRetroactiveModel.startTime;
        		 $scope.editRetroactiveModel.retroactive.endTime=$scope.editRetroactiveModel.endTime;
        		 $scope.editRetroactiveModel.retroactive.firstDate=$scope.editRetroactiveModel.retroactive.attendanceDate;
                 // 保存
                 Service.saveAcrossRetroactive($scope.editRetroactiveModel.retroactive,
                     function(data){
	                	 $scope.viewRetroactiveModel.unLoad();
	 					 $scope.viewModel.bindData();
                         $rootScope.alertInfo("跨天补签保存成功。");
                         $scope.viewModel.isLoading = false;
                     },function(data) {
                         $scope.viewModel.isLoading = false;
                         if (angular.isArray(data['fault'])) {
                             var faultMessage = [data['fault'][0]['message']].concat(data['fault'][0]['errorData']);
                             $rootScope.alertWarning(faultMessage);
                         } else {
                             $rootScope.alertWarning(data['fault']['message']);
                         }
                 });
        	}
        };
        //验证后保存一键补签
        $scope.viewModel.saveOnce=function(){
        	Service.saveOnceRetroactive($scope.editRetroactiveModel.retroactive,
    				function(data){
    					$scope.viewRetroactiveModel.unLoad();
    					$scope.viewModel.bindData();
    					$rootScope.alertInfo("补签申请提交成功。");
    					$scope.viewModel.isLoading = false;
    				},function(error) {
    					$rootScope.alertError(error.fault.message);
    					$scope.viewModel.isLoading = false;
    				});
        }
        
		//验证成功后保持
		$scope.viewModel.saveOn = function(){
			Service.saveRetroactive($scope.editRetroactiveModel.retroactive,
					function(data){
						$scope.viewRetroactiveModel.unLoad();
						$scope.viewModel.bindData();
						$rootScope.alertInfo("补签申请提交成功。");
						$scope.viewModel.isLoading = false;
					},function(error) {
						$rootScope.alertError(error.fault.message);
						$scope.viewModel.isLoading = false;
					});
		};
        
        $scope.viewRetroactiveModel.selected=function(role){
        	if(role.isRole==1){
        		$scope.editRetroactiveModel.retroactive.roleId=role.roleId;
        		return true;
        	}
        	return false;
        }; 
        
        $scope.editRetroactiveModel.rdoChecked=function(value){
			if($scope.editRetroactiveModel.retroactiveValue==value){
				return true;
			}
			return false;
        };

        $scope.editRetroactiveModel.onClick=function(value){
        	var retroctive=null;
			$scope.editRetroactiveModel.checkboxlength=0;
			$scope.editRetroactiveModel.type=0;
        	//处理选择框
        	for(var i=0;i<$scope.viewModel.dataList.length;i++){
        		if($scope.viewModel.dataList[i].checkbox){
        			retroctive=angular.copy($scope.viewModel.dataList[i]);
        			$scope.editRetroactiveModel.checkboxlength++;
        		}
        	}
        	if($scope.editRetroactiveModel.checkboxlength>1){
        		$rootScope.alertWarning("请选择一条考勤信息操作！");
        		return;
        	}
        	if(retroctive!=null){
    			$scope.editRetroactiveModel.startTime=retroctive.originalStartTime;
    			$scope.editRetroactiveModel.endTime=retroctive.originalEndTime;
        	}
        	$scope.editRetroactiveModel.retroactiveValue=value;
        	if(value=="1"){
        		$scope.editRetroactiveModel.type=0;
        	}else{
        		$scope.editRetroactiveModel.type=1;
        	}
  			$scope.editRetroactiveModel.retroactive.startTime=null;
    		$scope.editRetroactiveModel.retroactive.endTime=null;
        };

        /** 跨天补签 **/
        //跨天补签view
        $scope.viewAcrossModel={};
        $scope.viewAcrossModel.show=false;
		
		$scope.viewAcrossModel.unLoad=function(){
			$scope.viewAcrossModel.show=false;
        };
        //跨天补签
        $scope.viewAcrossModel.addAcrossR=function(){
            $scope.viewAcrossModel.load();
        };
        //加载跨天补签页面
        $scope.viewAcrossModel.load=function(){
        	$scope.viewAcrossModel.retroactive={};
			$scope.viewAcrossModel.retroactive.roleId=null;
			$scope.viewAcrossModel.retroactive.firstDate=null;
			$scope.viewAcrossModel.retroactive.startTime=null;
			$scope.viewAcrossModel.retroactive.endTime=null;
			$scope.viewAcrossModel.retroactive.description=null;
            $scope.viewModel.dataMorningList = null;
			$scope.viewAcrossModel.show=true;
			// if ($scope.viewAcrossForm.firstDate.$invalid) {
             //    $scope.viewAcrossForm.firstDate.$invalid = false;
			// }
        };
        // 跨天补签结束日
		$scope.viewAcrossModel.formatEndDate=function(date) {
			if ( date != null ) {
				var dateOut = new Date(date);
				dateOut.setDate(dateOut.getDate()+1);
				return dateOut;
			}
			return "";
		};
		$scope.viewAcrossModel.selected = function (role){
            if(role.isRole==1){
                $scope.viewAcrossModel.retroactive = $scope.viewAcrossModel.retroactive || {};
                $scope.viewAcrossModel.retroactive.roleId=role.roleId;
                return true;
            }
            return false;
        };
		// 跨天补签验证
		$scope.viewAcrossModel.requiredForm = function() {
			if($scope.viewAcrossModel.retroactive.firstDate==null){
				$scope.viewAcrossForm.firstDate.$invalid=true;
				$rootScope.alertWarning("签到日期请选择。");
				return true;
			}else{
				$scope.viewAcrossForm.firstDate.$invalid=false;
			}
			if ( $scope.viewAcrossModel.retroactive.startTime == null ) {
                $rootScope.alertWarning("下班签退时间请选择。");
                return true;
			}
            if ( $scope.viewAcrossModel.retroactive.endTime == null ) {
                $rootScope.alertWarning("上班签到时间请选择。");
                return true;
            }
			return false;
		};
        $scope.viewAcrossModel.save = function() {
        	if ($scope.viewAcrossModel.requiredForm()) {
        		return ;
			}
            $scope.viewModel.isLoading = true;
            // 保存
            Service.saveAcrossRetroactive($scope.viewAcrossModel.retroactive,
                function(data){
                    //保存成功
                    $scope.viewAcrossModel.unLoad();
                    $rootScope.alertInfo("跨天补签保存成功。");
                    $scope.viewModel.isLoading = false;
                },function(data) {
                    $scope.viewModel.isLoading = false;
                    if (angular.isArray(data['fault'])) {
                        var faultMessage = [data['fault'][0]['message']].concat(data['fault'][0]['errorData']);
                        $rootScope.alertWarning(faultMessage);
                    } else {
                        $rootScope.alertWarning(data['fault']['message']);
                    }
            });
		};
        //日期选择加载签到时间信息
        $scope.viewModel.attendanceDateChange=function(){
        	//获取基本信息
			Service.getCheckinoutMorningList({
				attendanceDate:$scope.viewAcrossModel.retroactive.firstDate
			},
			function(data){
				$scope.viewModel.dataMorningList = data;
				$scope.viewModel.isLoading=false;
			},function(error) {
				$scope.viewModel.isLoading=false;
			});
        };
        //
        $scope.viewModel.attendanceDateOpen2= function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			$("#rAStartTimehsdate").hide();
			$("#rAEndTimehsdate").hide();
			$scope.viewModel.attendanceDateOpened2 = !$scope.viewModel.attendanceDateOpened2;
		};


        /** 申请按钮 VIEW **/
		//申请按钮view
		$scope.viewButtonModel={};
        $scope.viewButtonModel.show0=false;
        $scope.viewButtonModel.show1=false;
        $scope.viewButtonModel.show2=false;
        $scope.viewButtonModel.show3=false;
        $scope.viewButtonModel.url = '';

		$scope.viewButtonModel.unLoad=function(){
			$scope.viewButtonModel.show0=false;
			$scope.viewButtonModel.show1=false;
			$scope.viewButtonModel.show2=false;
			$scope.viewButtonModel.show3=false;
            $scope.editModel.request={};
            $scope.editModel.request.startToTime=null;
            $scope.editModel.startToTimeShow = 1;
            $scope.editModel.marchtType=false;
            $scope.editModel.marchtData={};
            $scope.editModel.marchtYear="";
            $scope.editModel.marchtList=[];
            $scope.editModel1 = null;
        };
        //
        $scope.viewButtonModel.add = function(type){
        	var attendance=null;
        	var checkboxlength=0;
        	//处理选择框
        	for(var i=0;i<$scope.viewModel.dataList.length;i++){
        		if($scope.viewModel.dataList[i].checkbox){
        			attendance=angular.copy($scope.viewModel.dataList[i]);
        			checkboxlength++;
        		}
        	}
        	if(checkboxlength>1){
        		$rootScope.alertWarning("请选择一条考勤信息操作！");
        		return;
        	}
			$scope.viewButtonModel.bindData1(type, attendance);
			$scope.viewButtonModel.load(type);
        };

        $scope.viewButtonModel.load = function(type){
			$scope.viewButtonModel['show' + type] = true;
			if ( type == '0' ) {
                //小时控件
                $('#vStartTime0').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#vStartTime0').val())){
                            $scope.editForm0.vStartTime.$valid=true;
                            $scope.editForm0.vStartTime.$dirty=true;
                            $scope.editForm0.vStartTime.$invalid=false;
                            $scope.editModel0.request.startTime=$('#vStartTime0').val();
                            $scope.editModel0.dateChange();
                            $scope.editModel0.dateChangeType=false;
                        }else{
                            $('#vEhours0').val($scope.viewModel.toHourMinute(0));
                            $scope.editModel0.request.hours=0;
                        }
                    }
                });
                $('#vEndTime0').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#vEndTime0').val())){
                            $scope.editForm0.vEndTime.$valid=true;
                            $scope.editForm0.vEndTime.$dirty=true;
                            $scope.editForm0.vEndTime.$invalid=false;
                            $scope.editModel0.request.endTime=$('#vEndTime0').val();
                            $scope.editModel0.dateChange();
                            $scope.editModel0.dateChangeType=false;
                        }else{
                            $('#vEhours0').val($scope.viewModel0.toHourMinute(0));
                            $scope.editModel0.request.hours=0;
                        }
                    }
                });
                $('#vStartToTime0').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#vStartToTime0').val())){
                            $scope.editForm0.vStartToTime.$valid=true;
                            $scope.editForm0.vStartToTime.$dirty=true;
                            $scope.editForm0.vStartToTime.$invalid=false;
                            $scope.editModel0.request.startToTime=$('#vStartToTime0').val();
                            $scope.editModel0.dateChange();
                            $scope.editModel0.dateChangeType=false;
                        }else{
                            $('#vEhours0').val($scope.viewModel.toHourMinute(0));
                            $scope.editModel0.request.hours=0;
                        }
                    }
                });
                $scope.editModel0.dateChange();
                $scope.editModel0.selectRequestType();
			} else if ( type == '1' ) {
                $('#wStartTime1').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#wStartTime1').val())){
                            $scope.editForm1.wStartTime.$valid=true;
                            $scope.editForm1.wStartTime.$dirty=true;
                            $scope.editForm1.wStartTime.$invalid=false;
                            $scope.editModel1.request.startTime=$('#wStartTime1').val();
                            $scope.viewModel.dateChange(false);
                        }else{
                            $('#whours1').val($scope.viewModel1.toHourMinute(0));
                            $scope.editModel1.request.hours=0;
                        }
                    }
                });
                $('#wEndTime1').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#wEndTime1').val())){
                            $scope.editForm1.wEndTime.$valid=true;
                            $scope.editForm1.wEndTime.$dirty=true;
                            $scope.editForm1.wEndTime.$invalid=false;
                            $scope.editModel1.request.endTime=$('#wEndTime1').val();
                            $scope.viewModel.dateChange(false);
                        }else{
                            $('#whours1').val($scope.viewModel1.toHourMinute(0));
                            $scope.editModel1.request.hours=0;
                        }
                    }
                });
                $scope.editModel1.attendanceDateChange();
			} else if ( type == '2' ) {
                $('#bStartTime2').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#bStartTime2').val())){
                            $scope.editForm2.bStartTime.$valid=true;
                            $scope.editForm2.bStartTime.$dirty=true;
                            $scope.editForm2.bStartTime.$invalid=false;
                            $scope.editModel2.request.startTime=$('#bStartTime2').val();
                            $scope.editModel2.dateChange(false);
                        }else{
                            $('#bhours2').val($scope.viewModel.toHourMinute(0));
                            $scope.editModel2.request.hours=0;
                        }
                    }
                });
                $('#bEndTime2').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#bEndTime2').val())){
                            $scope.editForm2.bEndTime.$valid=true;
                            $scope.editForm2.bEndTime.$dirty=true;
                            $scope.editForm2.bEndTime.$invalid=false;
                            $scope.editModel2.request.endTime=$('#bEndTime2').val();
                            $scope.editModel2.dateChange(false);
                        }else{
                            $('#bhours2').val($scope.viewModel.toHourMinute(0));
                            $scope.editModel2.request.hours=0;
                        }
                    }
                });
                $('#bStartToTime2').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#bStartToTime2').val())){
                            $scope.editForm2.bStartToTime.$valid=true;
                            $scope.editForm2.bStartToTime.$dirty=true;
                            $scope.editForm2.bStartToTime.$invalid=false;
                            $scope.editModel2.request.startToTime=$('#bStartToTime2').val();
                            $scope.editModel2.dateChange(false);
                        }else{
                            $('#bhours2').val($scope.viewModel.toHourMinute(0));
                            $scope.editModel2.request.hours=0;
                        }
                    }
                });
                $scope.editModel2.dateChange(true);
			} else if ( type == '3' ) {
                $('#gStartTime3').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#gStartTime3').val())){
                            $scope.editForm3.gStartTime.$valid=true;
                            $scope.editForm3.gStartTime.$dirty=true;
                            $scope.editForm3.gStartTime.$invalid=false;
                            $scope.editModel3.request.startTime=$('#gStartTime3').val();
                            $scope.editModel3.dateChange(false);
                        }else{
                            $('#ghours3').val($scope.viewModel.toHourMinute(0));
                            $scope.editModel3.request.hours=0;
                        }
                    }
                });
                $('#gEndTime3').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#gEndTime3').val())){
                            $scope.editForm3.gEndTime.$valid=true;
                            $scope.editForm3.gEndTime.$dirty=true;
                            $scope.editForm3.gEndTime.$invalid=false;
                            $scope.editModel3.request.endTime=$('#gEndTime3').val();
                            $scope.editModel3.dateChange(false);
                        }else{
                            $('#ghours3').val($scope.viewModel.toHourMinute(0));
                            $scope.editModel3.request.hours=0;
                        }
                    }
                });
                $('#gStartToTime3').jHsDate({
                    format:'hh:mm',
                    callBack: function () {
                        if($scope.viewModel.escapeRegExp($('#gStartToTime3').val())){
                            $scope.editForm3.gStartToTime.$valid=true;
                            $scope.editForm3.gStartToTime.$dirty=true;
                            $scope.editForm3.gStartToTime.$invalid=false;
                            $scope.editModel3.request.startToTime=$('#gStartToTime3').val();
                            $scope.editModel3.dateChange(false);
                        }else{
                            $('#ghours3').val($scope.viewModel.toHourMinute(0));
                            $scope.editModel3.request.hours=0;
                        }
                    }
                });
                $scope.editModel3.dateChange(true);
			}
        };

        $scope.viewButtonModel.bindData1 = function(type, row) {
        	if ( type == '0' ) {
                //新增
                $scope.editModel0 = {};
                $scope.viewButtonModel.title="新增休假申请";
                $scope.editModel0.surplusHours=0;
                $scope.editModel0.surplusDayNumber=0;
                $scope.editModel0.type = true;
                $scope.editModel0.request={};
                $scope.editModel0.request.hours=0;
                $scope.editModel0.request.reportYear=null;
                $scope.editModel0.request.startToTime=null;
                if(row==null){
                	 $scope.editModel0.request.startDate=null;
                }else{
                	 var sDate = new Date(row.attendanceDate);
                     $scope.editModel0.request.startDate=sDate;
                }
                $scope.editModel0.request.endDate=null;
                $scope.editModel0.request.startTime=null;
                $scope.editModel0.request.endTime=null;
                $scope.editModel0.hours=null;
                $scope.editModel0.request.dayNumber=0;
                $scope.editModel0.request.requestType=0;
                $scope.editModel0.marchtYear="";
                $scope.editModel0.endDateOpened = false;
                $scope.editModel0.startDateOpened=false;
                if(!$scope.editModel0.dateChangeType){
                    $("#vEhours0").val("0");
                }
                if($scope.viewModel.roleList!=null){
                    for(var i = 0;$scope.viewModel.roleList.length>i ;i++){
                        if($scope.viewModel.roleList[i].isRole==1){
                            $scope.editModel0.request.roleId=$scope.viewModel.roleList[i].roleId;
                        }
                    }
                }
                //时间框失去焦点
                $scope.editModel0.dateChange=function(){
                    if($scope.editModel0.request.startDate <= $scope.editModel0.request.endDate){
                        $scope.editModel0.request.dayNumber=($scope.editModel0.request.endDate.getTime()-$scope.editModel0.request.startDate.getTime())/86400000+1;
                        $scope.editModel0.dayNumberShow = $scope.editModel0.request.dayNumber + "天";
                    }else{
                        $scope.editModel0.dayNumberShow = 0;
                    }
                    if($scope.editModel0.request.requestType==1
                        || $scope.editModel0.request.requestType==0
                        || $scope.editModel0.request.requestType==5
                        || $scope.editModel0.request.requestType==6
                        || $scope.editModel0.request.requestType==10){
                        if($scope.editModel0.request.startDate < $scope.editModel0.request.endDate){
                            $scope.viewModel.isLoading=true;
                            //获取基本信息
                            Service.getAttendanceCount({
                                    attendanceDate:$scope.editModel0.request.startDate,
                                },
                                function(data){
                                    $scope.editModel0.startToTimeShow = data;
                                    $scope.viewModel.isLoading=false;
                                },function(error) {
                                    $rootScope.alertError(error.fault.message);
                                    $scope.viewModel.isLoading=false;
                                });
                        }else{
                            $scope.editModel0.startToTimeShow = 1;
                            $scope.editModel0.request.startToTime = null;
                        }
                        $scope.editModel0.getRequestHours($scope.editModel0.startToTimeShow);
                    }
                };
                $scope.editModel0.getRequestHours=function(startToTimeShow){
                    if($scope.editModel0.request.endDate!=null
                        && $scope.editModel0.request.startDate!=null
                        && $scope.editModel0.request.startTime!=null
                        && $scope.editModel0.request.endDate!=null
                        && $scope.editModel0.request.endTime!=null
                        && $scope.editModel0.request.startDate!=null){
                        if($scope.editModel0.startToTimeShow==0){
                            if($scope.editModel0.request.startToTime==""
                                || $scope.editModel0.request.startToTime==null){
                                $scope.editModel0.request.hours = 0;
                                $scope.editModel0.hours=$scope.viewModel.toHourMinute($scope.editModel0.request.hours);
                                $('#vEhours0').val($scope.editModel0.hours);
                                return;
                            }else{
                                //判断结束时间是否小于开始时间
                                if($scope.editModel0.request.startTime>=$scope.editModel0.request.startToTime){
                                    $scope.editModel0.request.hours = 0;
                                    $scope.editModel0.hours=$scope.viewModel.toHourMinute($scope.editModel0.request.hours);
                                    $('#vEhours0').val($scope.editModel0.hours);
                                    return;
                                }
                            }
                        }
                        $scope.editModel0.hours=null;
                        $('#vEhours0').val($scope.editModel0.hours);
                        $request.getRequestHours($scope.editModel0.request,
                            function(data){
                                $scope.editModel0.request.hours = data;
                                $scope.editModel0.hours=$scope.viewModel.toHourMinute($scope.editModel0.request.hours);
                                $('#vEhours0').val($scope.editModel0.hours);
                            },function(error) {
                                $rootScope.alertError(error.fault.message);
                                $scope.editModel0.request.hours = 0;
                                $scope.editModel0.hours=$scope.viewModel.toHourMinute($scope.editModel0.request.hours);
                                $('#vEhours0').val($scope.editModel0.hours);
                            });
                    }else{
                        $scope.editModel0.request.hours=0;
                        $scope.editModel0.hours=$scope.viewModel.toHourMinute($scope.editModel0.request.hours);
                        $('#vEhours0').val($scope.editModel0.hours);
                    }
                };
                $scope.editModel0.startDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    if($scope.editModel0.endDateOpened){
                        $scope.editModel0.endDateOpened=false;
                    }
                    if($scope.editModel0.marryDateOpened){
                        $scope.editModel0.marryDateOpened=false;
                    }
                    $("#vStartTime0hsdate").hide();
                    $("#vStartToTime0hsdate").hide();
                    $("#vEndTime0hsdate").hide();
                    $scope.editModel0.startDateOpened = !$scope.editModel0.startDateOpened;
                };

                $scope.editModel0.endDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    if($scope.editModel0.startDateOpened){
                        $scope.editModel0.startDateOpened=false;
                    }
                    if($scope.editModel0.marryDateOpened){
                        $scope.editModel0.marryDateOpened=false;
                    }
                    $("#vStartTime0hsdate").hide();
                    $("#vStartToTime0hsdate").hide();
                    $("#vEndTime0hsdate").hide();
                    $scope.editModel0.endDateOpened= !$scope.editModel0.endDateOpened;
                };

                $scope.editModel0.marryDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    if($scope.editModel0.endDateOpened){
                        $scope.editModel0.endDateOpened=false;
                    }
                    if($scope.editModel0.startDateOpened){
                        $scope.editModel0.startDateOpened=false;
                    }
                    $("#vStartTime0hsdate").hide();
                    $("#vStartToTime0hsdate").hide();
                    $("#vEndTime0hsdate").hide();
                    $scope.editModel0.marryDateOpened= !$scope.editModel0.marryDateOpened;
                };

                //选择开始时间
                $scope.editModel0.startTimeClick=function(){
                    $("#vStartTime0hsdate").show();
                    $("#vStartToTime0hsdate").hide();
                    $("#vEndTime0hsdate").hide();
                    if($scope.editModel0.startDateOpened){
                        $scope.editModel0.startDateOpened=false;
                    }
                    if($scope.editModel0.endDateOpened){
                        $scope.editModel0.endDateOpened=false;
                    }
                };

                //选择至
                $scope.editModel0.startToTimeClick=function(){
                    $("#vStartTime0hsdate").hide();
                    $("#vStartToTime0hsdate").show();
                    $("#vEndTime0hsdate").hide();
                    if($scope.editModel0.marryDateOpened){
                        $scope.editModel0.marryDateOpened=false;
                    }
                    if($scope.editModel0.startDateOpened){
                        $scope.editModel0.startDateOpened=false;
                    }
                    if($scope.editModel0.endDateOpened){
                        $scope.editModel0.endDateOpened=false;
                    }
                };

                $scope.editModel0.endTimeClick=function(){
                    $("#vStartTime0hsdate").hide();
                    $("#vStartToTime0hsdate").hide();
                    $("#vEndTime0hsdate").show();
                    if($scope.editModel0.marryDateOpened){
                        $scope.editModel0.marryDateOpened=false;
                    }
                    if($scope.editModel0.startDateOpened){
                        $scope.editModel0.startDateOpened=false;
                    }
                    if($scope.editModel0.endDateOpened){
                        $scope.editModel0.endDateOpened=false;
                    }
                };
                //类型选择
                $scope.editModel0.selectRequestType = function(){
                    if($scope.editModel0.request.requestType!=12){
                        //判断年假，并判断开始日期，是否有1,2月份
                        if($scope.editModel0.request.requestType==1){
                            if($scope.editModel0.request.startDate!=null){
                                var year=$filter("date")($scope.editModel0.request.startDate, "yyyy");
                                var march=$filter("date")($scope.editModel0.request.startDate, "MM");
                                $scope.viewModel.isLoading=true;
                                //验证该时间是否可用去年年假
                                $request.getCheckYearFurlough({
                                        yearStr:year,
                                        monthStr:march
                                    },
                                    function(data){
                                        if(data){
                                            $scope.editModel0.getLastYearYearFurlough();
                                        }else{
                                            $scope.editModel0.marchtType=false;
                                            $scope.editModel0.getRestVacationByType();
                                            $scope.viewModel.isLoading=false;
                                        }
                                    },function(error) {
                                        $rootScope.alertError(error.fault.message);
                                        $scope.viewModel.isLoading=false;
                                    });
                            }
                        }else{
                            $scope.editModel0.marchtType=false;
                            $scope.editModel0.getRestVacationByType();
                        }
                    }
                };

                //查询去年年假和今年年假
                $scope.editModel0.getLastYearYearFurlough=function(){
                    $scope.viewModel.isLoading=true;
                    $scope.editModel0.marchtList=[];
                    $request.getLastYearYearFurlough({
                            startDate :$scope.editModel0.request.startDate,
                        },
                        function(data){
                            $scope.editModel0.marchtData=data;
                            //判断是否为修改年假
                            if($scope.editModel0.request.reportYear!=null){
                                $scope.editModel0.marchtYear=$scope.editModel0.request.reportYear+"";
                            }else{
                                $scope.editModel0.marchtYear="";
                            }
                            if($scope.editModel0.marchtData.lastYear!=null
                                && $scope.editModel0.marchtData.lastYearRestVacation!=0){
                                if($scope.editModel0.marchtYear==""){
                                    $scope.editModel0.marchtYear=$scope.editModel0.marchtData.lastYear;
                                }
                                var lateDate={};
                                lateDate.year=$scope.editModel0.marchtData.lastYear;
                                lateDate.vacation=$scope.editModel0.marchtData.lastYearRestVacation;
                                $scope.editModel0.marchtList.push(lateDate);
                            }
                            if($scope.editModel0.marchtData.thisYear!=null
                                && $scope.editModel0.marchtData.restVacation!=0){
                                if($scope.editModel0.marchtYear==""){
                                    $scope.editModel0.marchtYear=$scope.editModel0.marchtData.thisYear;
                                }
                                var thisDate={};
                                thisDate.year=$scope.editModel0.marchtData.thisYear;
                                thisDate.vacation=$scope.editModel0.marchtData.restVacation;
                                $scope.editModel0.marchtList.push(thisDate);
                            }
                            //如果为空
                            if($scope.editModel0.marchtList.length<=0){
                                $scope.editModel0.marchtYear=$scope.editModel0.marchtData.lastYear;
                                var lateDate={};
                                lateDate.year=$scope.editModel0.marchtData.lastYear;
                                lateDate.vacation=0;
                                $scope.editModel0.marchtList.push(lateDate);
                                var thisDate={};
                                thisDate.year=$scope.editModel0.marchtData.thisYear;
                                thisDate.vacation=0;
                                $scope.editModel0.marchtList.push(thisDate);
                            }
                            $scope.editModel0.marchtType=true;
                            $scope.viewModel.isLoading=false;
                        },function(error) {
                            $rootScope.alertError(error.fault.message);
                            $scope.viewModel.isLoading=false;
                        });
                };
                $scope.editModel0.selected=function(role){
                    if(role.isRole==1){
                        $scope.editModel0.request.roleId=role.roleId;
                        return true;
                    }
                    return false;
                };

                $scope.editModel0.getRestVacationByType=function(){
                    //获取基本信息
                    RestVacationService.getRestVacationByType({
                            furloughType : $scope.editModel0.request.requestType,
                            startDate :$scope.editModel0.request.startDate,
                        },
                        function(data){
                            if($scope.editModel0.request.requestType==0
                                || $scope.editModel0.request.requestType==5
                                || $scope.editModel0.request.requestType==6
                                || $scope.editModel0.request.requestType==10){

                                $scope.editModel0.surplusHours=data.restVacation; //data
                                if($scope.editModel0.surplusHours!=null){
                                    //$scope.editModel0.surplusHoursAndMin = Math.floor(a/60)+"小时"+ Math.floor(a%60)+"分钟";
                                    $scope.editModel0.surplusHoursAndMin =$scope.viewModel.toHourMinute($scope.editModel0.surplusHours);
                                }
                                //$scope.editModel0.surplusHoursShow =
                                $scope.editModel0.totalVacation=data.totalVacation;
                            }else if($scope.editModel0.request.requestType==3
                                || $scope.editModel0.request.requestType==4
                                || $scope.editModel0.request.requestType==11){
                                $scope.editModel0.surplusDayNumber=data.restVacation; //data
                                $scope.editModel0.surplusDayNumberShow=data.restVacation + "天";
                                $scope.editModel0.totalVacation=data.totalVacation;
                            }else if($scope.editModel0.request.requestType==1){
                                $scope.editModel0.surplusHours=data.restVacation; //data
                                if($scope.editModel0.surplusHours!=null){
                                    $scope.editModel0.surplusHoursAndMin =$scope.viewModel.toHourMinute($scope.editModel0.surplusHours);
                                }
                            }else if($scope.editModel0.request.requestType==13){
                                $scope.editModel0.surplusDayNumber=data.restVacation;
                                $scope.editModel0.surplusDayNumberShow=data.restVacation + "天";
                            }
                            $scope.viewModel.isLoading=false;
                        },function(error) {
                            $rootScope.alertError(error.fault.message);
                            $scope.viewModel.isLoading=false;
                        });
                };
                //验证
                $scope.viewButtonModel.requiredForm= function() {
                    if($scope.editModel0.request.requestType==12){
                        var type=false;
                        if(!$scope.editForm0.startDate.$valid){
                            $scope.editForm0.startDate.$dirty=true;
                            type=true;
                        }
                        if(!$scope.editForm0.description.$valid){
                            $scope.editForm0.description.$dirty=true;
                            type=true;
                        }
                        if(!$scope.editForm0.timeTnterval.$valid){
                            $scope.editForm0.timeTnterval.$dirty=true;
                            type=true;
                        }
                    }else if($scope.editModel0.request.requestType==1
                        || $scope.editModel0.request.requestType==0
                        || $scope.editModel0.request.requestType==5
                        || $scope.editModel0.request.requestType==6
                        || $scope.editModel0.request.requestType==10){
                        //验证小时类型
                        var type=false;
                        if(!$scope.editForm0.startDate.$valid){
                            $scope.editForm0.startDate.$dirty=true;
                            type=true;
                        }
                        if(!$scope.editForm0.endDate.$valid){
                            $scope.editForm0.endDate.$dirty=true;
                            type=true;
                        }
                        if(!$scope.editForm0.vStartTime.$valid){
                            $scope.editForm0.vStartTime.$dirty=true;
                            type=true;
                        }
                        if(!$scope.editForm0.vEndTime.$valid){
                            $scope.editForm0.vEndTime.$dirty=true;
                            type=true;
                        }
                        if(!$scope.editForm0.description.$valid){
                            $scope.editForm0.description.$dirty=true;
                            type=true;
                        }
                        if($scope.editModel0.startToTimeShow==0){
                            if($scope.editModel0.request.startToTime ==null
                                || $scope.editModel0.request.startToTime ==""){
                                $scope.editForm0.vStartToTime.$dirty=true;
                                $scope.editForm0.vStartToTime.$invalid=true;
                                return true;
                            }else{
                                $scope.editForm0.vStartToTime.$invalid=false;
                            }
                        }
                        //判断日期大小
                        if($scope.editModel0.request.startDate>$scope.editModel0.request.endDate){
                            $scope.editForm0.endDate.$invalid=false;
                            $rootScope.alertWarning("开始日期不能大于结束日期！");
                            return true;
                        }else{
                            if(!type){
                                $scope.editForm0.endDate.$invalid=false;
                            }
                        }
                        if($scope.editModel0.request.startDate < $scope.editModel0.request.endDate){
                            if($scope.editModel0.startToTimeShow==0){
                                if($scope.editModel0.request.startToTime ==""
                                    || $scope.editModel0.request.startToTime == null){
                                    $rootScope.alertWarning("未填写，结束时间，请确认。");
                                    $scope.editForm0.vStartToTime.$dirty=true;
                                    $scope.editForm0.vStartToTime.$invalid=true;
                                    return true;
                                }
                                if($scope.editModel0.request.startToTime <= $scope.editModel0.request.startTime){
                                    $rootScope.alertWarning("结束时间不能小于开始时间。");
                                    $scope.editForm0.vStartToTime.$dirty=true;
                                    $scope.editForm0.vStartToTime.$invalid=true;
                                    return true;
                                }
                                $scope.editForm0.vStartToTime.$invalid=false;
                            }
                        }

                        if($scope.editModel0.request.requestType==1){
                            if($scope.editModel0.request.hours<60){
                                $rootScope.alertWarning("年假低于一小时不允许申请。");
                                return true;
                            }
                            if($scope.editModel0.marchtType){
                                var yearHours=0;
                                for(var mi=0;mi<$scope.editModel0.marchtList.length;mi++){
                                    if($scope.editModel0.marchtList[mi].year==$scope.editModel0.marchtYear){
                                        yearHours=$scope.editModel0.marchtList[mi].vacation;
                                    }
                                }
                                if($scope.editModel0.request.hours>yearHours){
                                    $rootScope.alertWarning("休假时长不能超过可用时长。");
                                    return true;
                                }
                            }else{
                                if($scope.editModel0.request.hours>$scope.editModel0.surplusHours){
                                    $rootScope.alertWarning("休假时长不能超过可用时长。");
                                    return true;
                                }
                            }
                        }
                        else if($scope.editModel0.request.requestType==0){
                            if($scope.editModel0.request.hours<60){
                                $rootScope.alertWarning("调休低于一小时不允许申请。");
                                return true;
                            }
                            if($scope.editModel0.request.hours>$scope.editModel0.surplusHours){
                                $rootScope.alertWarning("休假时长不能超过可用时长。");
                                return true;
                            }
                        }else{
                            if(!$scope.editModel0.marchtType){
                                if(($scope.editModel0.surplusHours<=0
                                        || $scope.editModel0.surplusHours==null)
                                    && type==false){
                                    if($scope.editModel0.request.requestType==3){
                                        if($scope.editModel0.totalVacation==0){
                                        }else{
                                            $rootScope.alertWarning("没有可用时长，不能保存！");
                                            return true;
                                        }
                                    }else if($scope.editModel0.request.requestType!=4&&$scope.editModel0.request.requestType!=5&&$scope.editModel0.request.requestType!=6){
                                        $rootScope.alertWarning("没有可用时长，不能保存！");
                                        return true;
                                    }
                                }

                                //验证可用时长
                                if($scope.editModel0.request.hours/60 > $scope.editModel0.surplusHours){
                                    if($scope.editModel0.request.requestType==3){
                                        if($scope.editModel0.totalVacation==0){
                                        }else{
                                            $rootScope.alertWarning("不能超过可用时长：" + $scope.editModel0.surplusHours + "小时");
                                            return true;
                                        }
                                    }else if($scope.editModel0.request.requestType!=4&&$scope.editModel0.request.requestType!=5&&$scope.editModel0.request.requestType!=6){
                                        $rootScope.alertWarning("不能超过可用时长：" + $scope.editModel0.surplusHours + "小时");
                                        return true;
                                    }
                                }
                                $scope.editForm0.vStartToTime.$dirty=false;
                                $scope.editForm0.vStartToTime.$invalid=false;
                            }
                        }
                    }else if($scope.editModel0.request.requestType==3
                        || $scope.editModel0.request.requestType==4
                        || $scope.editModel0.request.requestType==11){
                        //验证天数类型
                        var type=false;
                        if(!$scope.editForm0.startDate.$valid){
                            $scope.editForm0.startDate.$dirty=true;
                            type=true;
                        }
                        if(!$scope.editForm0.endDate.$valid){
                            $scope.editForm0.endDate.$dirty=true;
                            type=true;
                        }
                        if(!$scope.editForm0.description.$valid){
                            $scope.editForm0.description.$dirty=true;
                            type=true;
                        }
                        //验证婚假
                        if($scope.editModel0.request.requestType==3){
                            if(!$scope.editForm0.marryDate.$valid){
                                $scope.editForm0.marryDate.$dirty=true;
                                type=true;
                            }
                            //结婚登记日起一年内生效，日期累加
                            var endMarryDate =angular.copy($scope.editModel0.request.marryDate);
                            endMarryDate.setFullYear(endMarryDate.getFullYear()+1);
                            //验证开始日期不能小于结婚登记日
                            if($scope.editModel0.request.startDate<$scope.editModel0.request.marryDate){
                                $rootScope.alertWarning("开始日期不能低于结婚登记日！");
                                return true;
                            }

                            //验证开始日期和结束日期是否在区间内
                            if( endMarryDate<$scope.editModel0.request.endDate){
                                $rootScope.alertWarning("结婚休假截止日："+$filter("date")(endMarryDate, "yyyy/MM/dd"));
                                return true;
                            }
                        }
                        //判断日期大小
                        if($scope.editModel0.request.startDate>$scope.editModel0.request.endDate){
                            $scope.editForm0.endDate.$invalid=false;
                            $rootScope.alertWarning("开始日期不能大于结束日期！");
                            return true;
                        }else{
                            if(!type){
                                $scope.editForm0.startDate.$invalid=false;
                                $scope.editForm0.endDate.$invalid=false;
                            }
                        }
                        if($scope.editModel0.surplusDayNumber<=0){
                            if($scope.editModel0.request.requestType==3){
                                if(!($scope.editModel0.totalVacation==0)){
                                    $rootScope.alertWarning("没有可用天数，不能保存！");
                                    return true;
                                }
                            }else if($scope.editModel0.request.requestType!=4&&$scope.editModel0.request.requestType!=5&&$scope.editModel0.request.requestType!=6){
                                $rootScope.alertWarning("没有可用天数，不能保存！");
                                return true;
                            }
                        }
                        //验证可用时长
                        if($scope.editModel0.request.dayNumber> $scope.editModel0.surplusDayNumber){
                            if($scope.editModel0.request.requestType==3){
                                if(!($scope.editModel0.totalVacation==0)){
                                    $rootScope.alertWarning("不能超过可用天数：" + $scope.editModel0.surplusDayNumber + "天");
                                    return true;
                                }
                            }else if($scope.editModel0.request.requestType!=4&&$scope.editModel0.request.requestType!=5&&$scope.editModel0.request.requestType!=6){
                                $rootScope.alertWarning("不能超过可用天数：" + $scope.editModel0.surplusDayNumber + "天");
                                return true;
                            }

                        }
                    }
                    return type;
                };

                //保存
                $scope.viewButtonModel.saveDate = function(){
                    //是否启动可用年假
                    if($scope.editModel0.marchtType){
                        $scope.editModel0.request.reportYear=$scope.editModel0.marchtYear;
                    }else{
                        var year=$filter("date")($scope.editModel0.request.startDate, "yyyy");
                        $scope.editModel0.request.reportYear=year;
                    }

                    if($scope.editModel0.request.requestType==3
                        || $scope.editModel0.request.requestType==4
                        || $scope.editModel0.request.requestType==11
                        || $scope.editModel0.request.requestType==13){
                        $scope.editModel0.request.hours=null;
                        $scope.editModel0.request.startTime=null;
                        $scope.editModel0.request.startToTime=null;
                        $scope.editModel0.request.endTime=null;
                    }else if($scope.editModel0.request.requestType==12){
                        $scope.editModel0.request.endDate=$scope.editModel0.request.startDate;
                        $scope.editModel0.request.hours=null;
                        $scope.editModel0.request.startTime=null;
                        $scope.editModel0.request.startToTime=null;
                        $scope.editModel0.request.endTime=null;
                    }
                    if($scope.editModel0.request.requestType==3){
                        $rootScope.alertConfirm("婚假申请必须为连续日期，不可分开申请。",function() {
                            $scope.viewModel.isLoading = true;
                            if($scope.editModel0.type){
                                $request.saveRequest($scope.editModel0.request,
                                    function(data){
                                        $scope.viewButtonModel.unLoad();
                                        $scope.viewModel.bindData();
                                        $rootScope.alertInfo("新增成功。");
                                        $scope.viewModel.isLoading = false;
                                    },function(error) {
                                    	if (angular.isArray(error['fault'])) {
			                                var faultMessage = error['fault'][0]['message'].concat(error['fault'][0]['errorData']);
			                                $rootScope.alertError(faultMessage);
			                            } else {
			                                $rootScope.alertError(error['fault']['message']);
			                            }
                                        $scope.viewModel.isLoading = false;
                                    });
                            }else{
                                $request.updateRequest($scope.editModel0.request,
                                    function(data){
                                        $scope.viewButtonModel.unLoad();
                                        $scope.viewModel.bindData();
                                        $rootScope.alertInfo("修改成功。");
                                        $scope.viewModel.isLoading = false;
                                    },function(error) {
                                    	if (angular.isArray(error['fault'])) {
			                                var faultMessage = error['fault'][0]['message'].concat(error['fault'][0]['errorData']);
			                                $rootScope.alertError(faultMessage);
			                            } else {
			                                $rootScope.alertError(error['fault']['message']);
			                            }
                                        $scope.viewModel.isLoading = false;
                                    });
                            }
                        });
                    }else{
                        $scope.viewModel.isLoading = true;
                        if($scope.editModel0.type){
                            $request.saveRequest($scope.editModel0.request,
                                function(data){
                                    $scope.viewButtonModel.unLoad();
                                    $scope.viewModel.bindData();
                                    $rootScope.alertInfo("新增成功。");
                                    $scope.viewModel.isLoading = false;
                                },function(error) {
                                	if (angular.isArray(error['fault'])) {
		                                var faultMessage = error['fault'][0]['message'].concat(error['fault'][0]['errorData']);
		                                $rootScope.alertError(faultMessage);
		                            } else {
		                                $rootScope.alertError(error['fault']['message']);
		                            }
                                    $scope.viewModel.isLoading = false;
                                });
                        }else{
                            $request.updateRequest($scope.editModel0.request,
                                function(data){
                                    $scope.viewButtonModel.unLoad();
                                    $scope.viewModel.bindData();
                                    $rootScope.alertInfo("修改成功。");
                                    $scope.viewModel.isLoading = false;
                                },function(error) {
                                	if (angular.isArray(error['fault'])) {
		                                var faultMessage = error['fault'][0]['message'].concat(error['fault'][0]['errorData']);
		                                $rootScope.alertError(faultMessage);
		                            } else {
		                                $rootScope.alertError(error['fault']['message']);
		                            }
                                    $scope.viewModel.isLoading = false;
                                });
                        }
                    }
                };
                //保存
                $scope.viewButtonModel.save0 = function(){
                    $scope.editModel0.request.approvalState=0;
                    if($scope.viewButtonModel.requiredForm()){
                        return;
                    }
                    $rootScope.alertConfirm("确定保存吗？",function() {
                        $scope.viewButtonModel.saveDate();
                    });
                };

                //保存并提交
                $scope.viewButtonModel.saveSubmit0 = function(){
                    $scope.editModel0.request.approvalState=1;
                    if($scope.viewButtonModel.requiredForm()){
                        return;
                    }
                    $rootScope.alertConfirm("确定保存并提交吗？",function() {
                        $scope.viewButtonModel.saveDate();
                    });
                };
                $scope.viewModel.dirty(type);
                $scope.editModel0.selectRequestType();
                //$scope.viewModel.load();
			} else if ( type == '1' ) {
				//加班申请
                $scope.viewButtonModel.title="新增加班申请";
                $scope.editModel1 = {};
                $scope.editModel1.type = true;
                $scope.editModel1.request={};
                $scope.editModel1.request.startTime=null;
                $scope.editModel1.request.endTime=null;

                if(row==null){
               	 	$scope.editModel1.request.startDate=null;
               	 	$scope.editModel1.request.endDate=null;
                }else{
                	var sDate = new Date(row.attendanceDate);
                    $scope.editModel1.request.startDate=sDate;
               	 	$scope.editModel1.request.endDate=sDate;
                }
                

                $scope.editModel1.request.overtimeType=3;
                $scope.editModel1.request.overtimeInterval=0;
                $scope.editModel1.overtimeInterval=0;    //段内休息时长
                $scope.editModel1.ahours=null;
                $scope.editModel1.hours=null;
                $scope.editModel1.request.requestType=7;
                $scope.editModel1.isRestDay=0;
                //日期启动开关
                $scope.editModel1.startDateOpened = false;
                $scope.editModel1.endDateOpened = false;
                $scope.editModel1.editStartDateOpened = false;
                $scope.editModel1.editEndDateOpened = false;
                $scope.viewModel.dirty(type);
                //时间框失去焦点
                $scope.viewModel.dateChange=function(type){
                    $scope.viewModel.getRequestHours();
                };
                //选择加班类型
                $scope.viewModel.overtimeTypeChange=function(){
                    $scope.viewModel.dateChange(true);
                };
                //日期选择加载签到时间信息
                $scope.editModel1.attendanceDateChange=function(){
                    //获取基本信息
                    $request.getAttendanceTime({
                            attendanceDate:$scope.editModel1.request.startDate
                        },
                        function(data){
                            $scope.editModel1.isRestDay=data.isRestDay;
                            //如果为正常日期
                            if($scope.editModel1.isRestDay==0){
                                //并且原有修改为休息日，默认为晚上
                                if($scope.editModel1.request.overtimeType==2){
                                    $scope.editModel1.request.overtimeType=3;
                                }
                            }
                            if($scope.editModel1.type){
                                $scope.editModel1.overtimeInterval=0;
                            }else{
                                if($scope.editModel1.overtimeInterval!=$scope.editModel1.request.overtimeInterval){
                                    $scope.editModel1.overtimeInterval=0;
                                }
                            }
                            $scope.editModel1.startTime=data.startTime;
                            $scope.editModel1.endTime=data.endTime;
                            $scope.editModel1.request.endTime=data.endTime;
                            $scope.viewModel.dateChange(true);
                        },function(error) {});
                };
                $scope.viewModel.getRequestHours=function(){
                    if($scope.editModel1.request.startTime!=null
                        && $scope.editModel1.request.endDate!=null
                        && $scope.editModel1.request.endTime!=null
                        && $scope.editModel1.request.startDate!=null){
                        //判断日期类型是否为正常日
                        if($scope.editModel1.isRestDay==0){
                            //判断是否为早上加班
                            if($scope.editModel1.request.overtimeType==4){
                                $request.getMorningMinutes($scope.editModel1.request,
                                    function(data){
                                        $scope.editModel1.request.hours =data;
                                        $scope.editModel1.ahours= $scope.editModel1.request.hours;
                                        $scope.editModel1.hours=$scope.viewModel.toHourMinute($scope.editModel1.request.hours);
                                        $('#whours1').val($scope.editModel1.hours);
                                        $scope.viewModel.overtimeChange();
                                    },function(error) {
                                        $rootScope.alertError(error.fault.message);
                                        $scope.editModel1.request.hours =0;
                                        $scope.editModel1.ahours= $scope.editModel1.request.hours;
                                        $scope.editModel1.hours=$scope.viewModel.toHourMinute($scope.editModel1.request.hours);
                                        $('#whours1').val($scope.editModel1.hours);
                                        $scope.viewModel.isLoading = false;
                                    });
                            }else{
                                $scope.viewModel.toGetRequestHours();
                            }
                        }else{
                            $scope.viewModel.toGetRequestHours();
                        }
                    }
                };

                //获取小时数
                $scope.viewModel.toGetRequestHours=function(){
                    $request.getRequestHours($scope.editModel1.request,
                        function(data){
                            $scope.editModel1.request.hours =data;
                            $scope.editModel1.ahours= $scope.editModel1.request.hours;
                            $scope.editModel1.hours=$scope.viewModel.toHourMinute($scope.editModel1.request.hours);
                            $('#whours1').val($scope.editModel1.hours);
                            $scope.viewModel.overtimeChange();
                        },function(error) {
                            $rootScope.alertError(error.fault.message);
                            $scope.editModel1.request.hours =0;
                            $scope.editModel1.ahours= $scope.editModel1.request.hours;
                            $scope.editModel1.hours=$scope.viewModel.toHourMinute($scope.editModel1.request.hours);
                            $('#whours1').val($scope.editModel1.hours);
                            $scope.viewModel.isLoading = false;
                        });
                };
                //起止日期选择
                $scope.editModel1.startDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    $scope.editModel1.startDateOpened = !$scope.editModel1.startDateOpened;
                };

                //起止日期选择
                $scope.editModel1.endDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    $scope.editModel1.endDateOpened = !$scope.editModel1.endDateOpened;
                };

                $scope.editModel1.editStartDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    if($scope.editModel1.editEndDateOpened){
                        $scope.editModel1.editEndDateOpened=false;
                    }
                    $("#wStartTime1hsdate").hide();
                    $("#wEndTime1hsdate").hide();
                    $scope.editModel1.editStartDateOpened = !$scope.editModel1.editStartDateOpened;
                };

                $scope.editModel1.editEndDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    if($scope.editModel1.editStartDateOpened){
                        $scope.editModel1.editStartDateOpened=false;
                    }
                    $("#wStartTime1hsdate").hide();
                    $("#wEndTime1hsdate").hide();
                    $scope.editModel1.editEndDateOpened = !$scope.editModel1.editEndDateOpened;
                };

                //选择开始时间
                $scope.editModel1.startTimeClick=function(){
                    $("#wStartTime1hsdate").show();
                    $("#wEndTime1hsdate").hide();
                    if($scope.editModel1.editStartDateOpened){
                        $scope.editModel1.editStartDateOpened=false;
                    }
                    if($scope.editModel1.editEndDateOpened){
                        $scope.editModel1.editEndDateOpened=false;
                    }
                };

                $scope.editModel1.endTimeClick=function(){
                    $("#wStartTime1hsdate").hide();
                    $("#wEndTime1hsdate").show();
                    if($scope.editModel1.editStartDateOpened){
                        $scope.editModel1.editStartDateOpened=false;
                    }
                    if($scope.editModel1.editEndDateOpened){
                        $scope.editModel1.editEndDateOpened=false;
                    }
                };
                //修改段内时间
                $scope.viewModel.overtimeChange=function(){
                    if($scope.editModel1.overtimeInterval!=0 && $scope.editModel1.overtimeInterval!=null){
                        var overtimeInterval=$scope.editModel1.overtimeInterval;
                        if($scope.editModel1.request.hours>0 && overtimeInterval!=0){
                            $scope.editModel1.request.hours=$scope.editModel1.ahours-overtimeInterval;
                            $scope.editModel1.hours=$scope.viewModel.toHourMinute($scope.editModel1.request.hours);
                            $('#whours1').val($scope.editModel1.hours);
                        }
                    }else if($scope.editModel1.overtimeInterval==0 && $scope.editModel1.overtimeInterval!=null){
                        $scope.editModel1.request.hours=$scope.editModel1.ahours;
                        $scope.editModel1.hours=$scope.viewModel.toHourMinute($scope.editModel1.request.hours);
                        $('#whours1').val($scope.editModel1.hours);
                    }
                };
                $scope.editModel1.selected=function(role){
                    if(role.isRole==1){
                        $scope.editModel1.request.roleId=role.roleId;
                        return true;
                    }
                    return false;
                };
                //验证
                $scope.viewButtonModel.requiredForm= function() {
                    if (!$scope.editForm1.startDate.$valid
                        || !$scope.editForm1.wStartTime.$valid
                        || !$scope.editForm1.endDate.$valid
                        || !$scope.editForm1.wEndTime.$valid
                        || !$scope.editForm1.description.$valid) {

                        if(!$scope.editForm1.startDate.$dirty){
                            $scope.editForm1.startDate.$dirty=true;
                        }
                        if(!$scope.editForm1.wStartTime.$dirty){
                            $scope.editForm1.wStartTime.$dirty=true;
                        }
                        if(!$scope.editForm1.endDate.$dirty){
                            $scope.editForm1.endDate.$dirty=true;
                        }
                        if(!$scope.editForm1.wEndTime.$dirty){
                            $scope.editForm1.wEndTime.$dirty=true;
                        }
                        if(!$scope.editForm1.description.$dirty){
                            $scope.editForm1.description.$dirty=true;
                        }
                        return true;
                    }else{
                        if($scope.editModel1.request.startDate>$scope.editModel1.request.endDate){
                            $scope.editForm1.endDate.$invalid=true;
                            return true;
                        }
                        if($scope.editModel1.request.hours<60 || $scope.editModel1.request.hours==0){
                            $rootScope.alertWarning("加班低于一小时不允许申请。");
                            return true;
                        }
                        //如果为早上加班，开始日期和结束日期，需要相等
                        if($scope.editModel1.request.overtimeType==4){
                            if($scope.editModel1.request.startDate.getTime()!=$scope.editModel1.request.endDate.getTime()){
                                $rootScope.alertWarning("开始日期和结束日期不符，请重新选择！");
                                $scope.editForm1.endDate.$invalid=true;
                                return true;
                            }
                        }
                        $scope.editForm1.endDate.$invalid=false;
                        return false;
                    }
                };
                $scope.viewModel.saveDate = function(){
                    $scope.editModel1.request.overtimeInterval=$scope.editModel1.overtimeInterval;
                    $scope.viewModel.isLoading = true;
                    //判断如果为休息日，加班类型为空
                    if($scope.editModel1.isRestDay==1){
                        //表示为休息日或节假日类型
                        $scope.editModel1.request.overtimeType=2;
                    }
                    if($scope.editModel1.type){
                        $request.saveRequest($scope.editModel1.request,
                            function(data){
                                $scope.viewButtonModel.unLoad();
                                $scope.viewModel.bindData();
                                $rootScope.alertInfo("新增成功。");
                                $scope.viewModel.isLoading = false;
                            },function(error) {
                                $rootScope.alertError(error.fault.message);
                                $scope.viewModel.isLoading = false;
                            });
                    }else{
                        $request.updateRequest($scope.editModel1.request,
                            function(data){
                                $scope.viewButtonModel.unLoad();
                                $scope.viewModel.bindData();
                                $rootScope.alertInfo("修改成功。");
                                $scope.viewModel.isLoading = false;
                            },function(error) {
                                $rootScope.alertError(error.fault.message);
                                $scope.viewModel.isLoading = false;
                            });
                    }
                };
                
                //保存
                $scope.viewButtonModel.save1 = function(){
                    $scope.editModel1.request.approvalState=0;
                    if($scope.viewButtonModel.requiredForm()){
                        return;
                    }
                    $rootScope.alertConfirm("确定保存吗？",function() {
                        $scope.viewModel.saveDate();
                    });
                };

                //提交
                $scope.viewButtonModel.saveSubmit1 = function(){
                    $scope.editModel1.request.approvalState=1;
                    if($scope.viewButtonModel.requiredForm()){
                        return;
                    }
                    $rootScope.alertConfirm("确定保存并提交吗？",function() {
                        $scope.viewModel.saveDate();
                    });
                };
			} else if ( type == '2' ) {
                $scope.viewButtonModel.title="新增出差申请";
                $scope.editModel2 = {};
                $scope.editModel2.type = true;
                $scope.editModel2.request={};
                if(row==null){
                	$scope.editModel2.request.startDate=null;
                    $scope.editModel2.request.endDate=null;
                }else{
            	    var sDate = new Date(row.attendanceDate);
                    $scope.editModel2.request.startDate=sDate;
                    $scope.editModel2.request.endDate=sDate;
                }
                $scope.editModel2.request.startTime=null;
                $scope.editModel2.request.endTime=null;
                $scope.editModel2.hours=null;
                $scope.editModel2.request.requestType=8;
                $scope.viewModel.dirty(type);
                $scope.editModel2.editStartDateOpened = false;
                $scope.editModel2.editEndDateOpened = false;
                
                $scope.editModel2.selected=function(role){
                    if(role.isRole==1){
                        $scope.editModel2.request.roleId=role.roleId;
                        return true;
                    }
                    return false;
                };
                
                //时间框失去焦点
                $scope.editModel2.dateChange=function(type){  	
                    if($scope.editModel2.request.startDate!=null
                        && $scope.editModel2.request.endDate!=null){
                        if($scope.editModel2.request.startDate < $scope.editModel2.request.endDate){
                            //获取基本信息
                            Service.getAttendanceCount({
                                    attendanceDate:$scope.editModel2.request.startDate,
                                },
                                function(data){
                                    $scope.editModel2.startToTimeShow = data;
                                },function(error) {
                                    //$rootScope.alertError(error.fault.message);
                                });
                        }else{
                            $scope.editModel2.startToTimeShow = 1;
                            $scope.editModel2.request.startToTime = "";
                        }
                        $scope.editModel2.getRequestHours($scope.editModel2.startToTimeShow);
                    }
                };
                
                $scope.editModel2.editStartDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    if($scope.editModel2.editEndDateOpened){
                        $scope.editModel2.editEndDateOpened=false;
                    }
                    $("#bStartTime2hsdate").hide();
                    $("#bStartToTime2hsdate").hide();
                    $("#bEndTime2hsdate").hide();
                    $scope.editModel2.editStartDateOpened = !$scope.editModel2.editStartDateOpened;
                };

                $scope.editModel2.editEndDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    if($scope.editModel2.editStartDateOpened){
                        $scope.editModel2.editStartDateOpened=false;
                    }
                    $("#bStartTime2hsdate").hide();
                    $("#bStartToTime2hsdate").hide();
                    $("#bEndTime2hsdate").hide();
                    $scope.editModel2.editEndDateOpened = !$scope.editModel2.editEndDateOpened;
                };

                //选择开始时间
                $scope.editModel2.startTimeClick=function(){
                    $("#bStartTime2hsdate").show();
                    $("#bStartToTime2hsdate").hide();
                    $("#bEndTime2hsdate").hide();
                    if($scope.editModel2.editStartDateOpened){
                        $scope.editModel2.editStartDateOpened=false;
                    }
                    if($scope.editModel2.editEndDateOpened){
                        $scope.editModel2.editEndDateOpened=false;
                    }
                };

                //选择至
                $scope.editModel2.startToTimeClick=function(){
                    $("#bStartTime2hsdate").hide();
                    $("#bStartToTime2hsdate").show();
                    $("#bEndTime2hsdate").hide();
                    if($scope.editModel2.editStartDateOpened){
                        $scope.editModel2.editStartDateOpened=false;
                    }
                    if($scope.editModel2.editEndDateOpened){
                        $scope.editModel2.editEndDateOpened=false;
                    }
                };

                $scope.editModel2.endTimeClick=function(){
                    $("#bStartTime2hsdate").hide();
                    $("#bStartToTime2hsdate").hide();
                    $("#bEndTime2hsdate").show();
                    if($scope.editModel2.editStartDateOpened){
                        $scope.editModel2.editStartDateOpened=false;
                    }
                    if($scope.editModel2.editEndDateOpened){
                        $scope.editModel2.editEndDateOpened=false;
                    }
                };

                $scope.editModel2.getRequestHours=function(startToTimeShow){
                    if($scope.editModel2.request.endDate!=null
                        && $scope.editModel2.request.startDate!=null
                        && $scope.editModel2.request.startTime!=null
                        && $scope.editModel2.request.endDate!=null
                        && $scope.editModel2.request.endTime!=null
                        && $scope.editModel2.request.startDate!=null){
                        if($scope.editModel2.startToTimeShow==0){
                            if($scope.editModel2.request.startToTime==""
                                || $scope.editModel2.request.startToTime==null){
                                $scope.editModel2.request.hours = 0;
                                $scope.editModel2.hours=$scope.viewModel.toHourMinute($scope.editModel2.request.hours);
                                $('#bhours2').val($scope.editModel2.hours);
                                return;
                            }else{
                                //判断结束时间是否小于开始时间
                                if($scope.editModel2.request.startTime>=$scope.editModel2.request.startToTime){
                                    $scope.editModel2.request.hours = 0;
                                    $scope.editModel2.hours=$scope.viewModel.toHourMinute($scope.editModel2.request.hours);
                                    $('#ghours2').val($scope.editModel2.hours);
                                    return;
                                }
                            }
                        }
                        $scope.editModel2.hours=null;
                        $('#bhours2').val($scope.editModel2.hours);
                        $request.getRequestHours($scope.editModel2.request,
                            function(data){
                                $scope.editModel2.request.hours = data;
                                $scope.editModel2.hours=$scope.viewModel.toHourMinute($scope.editModel2.request.hours);
                                $('#bhours2').val($scope.editModel2.hours);
                            },function(error) {
                                $rootScope.alertError(error.fault.message);
                                $scope.editModel2.request.hours = 0;
                                $scope.editModel2.hours=$scope.viewModel.toHourMinute($scope.editModel2.request.hours);
                                $('#bhours2').val($scope.editModel2.hours);
                            });
                    }else{
                        $scope.editModel2.request.hours=0;
                        $scope.editModel2.hours=$scope.viewModel.toHourMinute($scope.editModel2.request.hours);
                        $('#bhours2').val($scope.editModel2.hours);
                    }
                    $scope.viewModel.dirty(type);
                };
                
                //验证
                $scope.viewButtonModel.requiredForm= function() {
                    if (!$scope.editForm2.startDate.$valid
                        || !$scope.editForm2.bStartTime.$valid
                        || !$scope.editForm2.endDate.$valid
                        || !$scope.editForm2.bEndTime.$valid
                        || !$scope.editForm2.description.$valid) {
                        if(!$scope.editForm2.startDate.$dirty){
                            $scope.editForm2.startDate.$dirty=true;
                        }
                        if(!$scope.editForm2.bStartTime.$dirty){
                            $scope.editForm2.bStartTime.$dirty=true;
                        }
                        if(!$scope.editForm2.endDate.$dirty){
                            $scope.editForm2.endDate.$dirty=true;
                        }
                        if(!$scope.editForm2.bEndTime.$dirty){
                            $scope.editForm2.bEndTime.$dirty=true;
                        }
                        if(!$scope.editForm2.description.$dirty){
                            $scope.editForm2.description.$dirty=true;
                        }
                        if($scope.editModel2.startToTimeShow==0){
                            if($scope.editModel2.request.startToTime ==null
                                || $scope.editModel2.request.startToTime ==""){
                                $scope.editForm2.bStartToTime.$dirty=true;
                                $scope.editForm2.bStartToTime.$invalid=true;
                                return true;
                            }else{
                                $scope.editForm2.bStartToTime.$invalid=false;
                            }
                        }
                        return true;
                    }else{
                        if($scope.editModel2.startToTimeShow==0){
                            if($scope.editModel2.request.startToTime ==null
                                || $scope.editModel2.request.startToTime ==""){
                                $scope.editForm2.bStartToTime.$dirty=true;
                                $scope.editForm2.bStartToTime.$invalid=true;
                                return true;
                            }else{
                                $scope.editForm2.bStartToTime.$invalid=false;
                            }
                        }
                        if($scope.editModel2.request.startDate>$scope.editModel2.request.endDate){
                            $scope.editForm2.endDate.$invalid=true;
                            return true;
                        }
                        if($scope.editModel2.request.startDate < $scope.editModel2.request.endDate){
                            if($scope.editModel2.startToTimeShow==0){
                                if($scope.editModel2.request.startToTime ==null
                                    || $scope.editModel2.request.startToTime ==""){
                                    $rootScope.alertWarning("未填写，结束时间，请确认。");
                                    $scope.editForm2.bStartToTime.$dirty=true;
                                    $scope.editForm2.bStartToTime.$invalid=true;
                                    return true;
                                }
                                if($scope.editModel2.request.startTime>=$scope.editModel2.request.startToTime){
                                    $rootScope.alertWarning("结束时间不能小于开始时间。");
                                    $scope.editForm2.bStartToTime.$dirty=true;
                                    $scope.editForm2.bStartToTime.$invalid=true;
                                    return true;
                                }
                                $scope.editForm2.bStartToTime.$invalid=false;
                            }
                        }
                        if($scope.editModel2.request.hours<=0){
                            $rootScope.alertWarning("出差时长不能为0小时，请确认！");
                            $scope.editForm2.bEndTime.$invalid=true;
                            return true;
                        }
                        if($scope.editModel2.request.hours<60){
                            $rootScope.alertWarning("出差低于一小时不允许申请。");
                            return true;
                        }
                        $scope.editForm2.endDate.$invalid=false;
                        return false;
                    }
                };

                $scope.viewButtonModel.saveDate = function(){
                    $scope.viewModel.isLoading = true;
                    if($scope.editModel2.type){
                        $request.saveRequest($scope.editModel2.request,
                            function(data){
                                $scope.viewButtonModel.unLoad();
                                $scope.viewModel.bindData();
                                $rootScope.alertInfo("新增成功。");
                                $scope.viewModel.isLoading = false;
                            },function(error) {
                                $rootScope.alertError(error.fault.message);
                                $scope.viewModel.isLoading = false;
                            });
                    }else{
                        $request.updateRequest($scope.editModel2.request,
                            function(data){
                                $scope.viewButtonModel.unLoad();
                                $scope.viewModel.bindData();
                                $rootScope.alertInfo("修改成功。");
                                $scope.viewModel.isLoading = false;
                            },function(error) {
                                $rootScope.alertError(error.fault.message);
                                $scope.viewModel.isLoading = false;
                            });
                    }
                }
                
                //保存
                $scope.viewButtonModel.save2 = function(){
                    $scope.editModel2.request.approvalState=0;
                    if($scope.viewButtonModel.requiredForm()){
                        return;
                    }
                    $rootScope.alertConfirm("确定保存吗？",function() {
                        $scope.viewButtonModel.saveDate();
                    });
                };

                //提交
                $scope.viewButtonModel.saveSubmit2 = function(){
                    $scope.editModel2.request.approvalState=1;
                    if($scope.viewButtonModel.requiredForm()){
                        return;
                    }
                    $rootScope.alertConfirm("确定保存并提交吗？",function() {
                        $scope.viewButtonModel.saveDate();
                    });
                };
			} else if ( type == '3' ) {
                $scope.viewButtonModel.title="新增外出申请";
                $scope.editModel3 = {};
                $scope.editModel3.type = true;
                $scope.editModel3.request={};
                if(row==null){
                	$scope.editModel3.request.startDate=null;
                    $scope.editModel3.request.endDate=null;
                }else{
            	    var sDate = new Date(row.attendanceDate);
                    $scope.editModel3.request.startDate=sDate;
                    $scope.editModel3.request.endDate=sDate;
                }
                $scope.editModel3.request.startToTime=null;
                $scope.editModel3.request.startTime=null;
                $scope.editModel3.request.endTime=null;
                $scope.editModel3.request.startToTime=null;
                $scope.editModel3.hours=null;
                $scope.editModel3.request.dayNumber=0;
                $scope.editModel3.request.requestType=9;
                $scope.editModel3.request.hours=null;
                $scope.editModel3.editStartDateOpened = false;
                $scope.editModel3.editEndDateOpened = false;
                $scope.viewModel.dirty(type);

                $scope.editModel3.selected=function(role){
                    if(role.isRole==1){
                        $scope.editModel3.request.roleId=role.roleId;
                        return true;
                    }
                    return false;
                };
                //时间框失去焦点
                $scope.editModel3.dateChange=function(){
                    if($scope.editModel3.request.startDate!=null
                        && $scope.editModel3.request.endDate!=null){
                        if($scope.editModel3.request.startDate < $scope.editModel3.request.endDate){
                            //获取基本信息
                            Service.getAttendanceCount({
                                    attendanceDate:$scope.editModel3.request.startDate,
                                },
                                function(data){
                                    $scope.editModel3.startToTimeShow = data;
                                },function(error) {
                                    $rootScope.alertError(error.fault.message);
                                });
                        }else{
                            $scope.editModel3.startToTimeShow = 1;
                            $scope.editModel3.request.startToTime = "";
                        }
                        $scope.editModel3.getRequestHours();
                    }
                };
                
                $scope.editModel3.getRequestHours=function(){
                    if($scope.editModel3.request.endDate!=null
                        && $scope.editModel3.request.startDate!=null
                        && $scope.editModel3.request.startTime!=null
                        && $scope.editModel3.request.endDate!=null
                        && $scope.editModel3.request.endTime!=null
                        && $scope.editModel3.request.startDate!=null){
                        if($scope.editModel3.startToTimeShow==0){
                            if($scope.editModel3.request.startToTime==""
                                || $scope.editModel3.request.startToTime==null){
                                $scope.editModel3.request.hours = 0;
                                $scope.editModel3.hours=$scope.viewModel.toHourMinute($scope.editModel3.request.hours);
                                $('#ghours3').val($scope.editModel3.hours);
                                return;
                            }else{
                                //判断结束时间是否小于开始时间
                                if($scope.editModel3.request.startTime>=$scope.editModel3.request.startToTime){
                                    $scope.editModel3.request.hours = 0;
                                    $scope.editModel3.hours=$scope.viewModel.toHourMinute($scope.editModel3.request.hours);
                                    $('#ghours3').val($scope.editModel3.hours);
                                    return;
                                }
                            }
                        }
                        $scope.editModel3.hours=null;
                        $('#ghours3').val($scope.editModel3.hours);
                        $request.getRequestHours($scope.editModel3.request,
                            function(data){
                                $scope.editModel3.request.hours = data;
                                $scope.editModel3.hours=$scope.viewModel.toHourMinute($scope.editModel3.request.hours);
                                $('#ghours3').val($scope.editModel3.hours);
                            },function(error) {
                                $rootScope.alertError(error.fault.message);
                                $scope.editModel3.request.hours = 0;
                                $scope.editModel3.hours=$scope.viewModel.toHourMinute($scope.editModel3.request.hours);
                                $('#ghours3').val($scope.editModel3.hours);
                            });
                    }else{
                        $scope.editModel3.request.hours=0;
                        $scope.editModel3.hours=$scope.viewModel.toHourMinute($scope.editModel3.request.hours);
                        $('#ghours3').val($scope.editModel3.hours);
                    }
                };

                $scope.editModel3.editStartDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    if($scope.editModel3.editEndDateOpened){
                        $scope.editModel3.editEndDateOpened=false;
                    }
                    $("#gStartTime3hsdate").hide();
                    $("#gStartToTime3hsdate").hide();
                    $("#gEndTime3hsdate").hide();
                    $scope.editModel3.editStartDateOpened = !$scope.editModel3.editStartDateOpened;
                };

                $scope.editModel3.editEndDateOpen = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    if($scope.editModel3.editStartDateOpened){
                        $scope.editModel3.editStartDateOpened=false;
                    }
                    $("#gStartTime3hsdate").hide();
                    $("#gStartToTime3hsdate").hide();
                    $("#gEndTime3hsdate").hide();
                    $scope.editModel3.editEndDateOpened = !$scope.editModel3.editEndDateOpened;
                };

                //选择开始时间
                $scope.editModel3.startTimeClick=function(){
                    $("#gStartTimeh3hsdate").show();
                    $("#gStartToTime3hsdate").hide();
                    $("#gEndTime3hsdate").hide();
                    if($scope.editModel3.editStartDateOpened){
                        $scope.editModel3.editStartDateOpened=false;
                    }
                    if($scope.editModel3.editEndDateOpened){
                        $scope.editModel3.editEndDateOpened=false;
                    }
                };

                //选择至
                $scope.editModel3.startToTimeClick=function(){
                    $("#gStartTime3hsdate").hide();
                    $("#gStartToTime3hsdate").show();
                    $("#gEndTime3hsdate").hide();
                    if($scope.editModel3.editStartDateOpened){
                        $scope.editModel3.editStartDateOpened=false;
                    }
                    if($scope.editModel3.editEndDateOpened){
                        $scope.editModel3.editEndDateOpened=false;
                    }
                };

                $scope.editModel3.endTimeClick=function(){
                    $("#gStartTime3hsdate").hide();
                    $("#gStartToTime3hsdate").hide();
                    $("#gEndTime3hsdate").show();
                    if($scope.editModel3.editStartDateOpened){
                        $scope.editModel3.editStartDateOpened=false;
                    }
                    if($scope.editModel3.editEndDateOpened){
                        $scope.editModel3.editEndDateOpened=false;
                    }
                };

                //验证
                $scope.viewButtonModel.requiredForm= function() {
                    if (!$scope.editForm3.startDate.$valid
                        || !$scope.editForm3.gStartTime.$valid
                        || !$scope.editForm3.endDate.$valid
                        || !$scope.editForm3.gEndTime.$valid
                        || !$scope.editForm3.description.$valid) {
                        if(!$scope.editForm3.startDate.$dirty){
                            $scope.editForm3.startDate.$dirty=true;
                        }
                        if(!$scope.editForm3.gStartTime.$dirty){
                            $scope.editForm3.gStartTime.$dirty=true;
                        }
                        if(!$scope.editForm3.endDate.$dirty){
                            $scope.editForm3.endDate.$dirty=true;
                        }
                        if(!$scope.editForm3.gEndTime.$dirty){
                            $scope.editForm3.gEndTime.$dirty=true;
                        }
                        if(!$scope.editForm3.description.$dirty){
                            $scope.editForm3.description.$dirty=true;
                        }
                        if(!$scope.editForm3.roleId.$dirty){
                            $scope.editForm3.roleId.$dirty=true;
                        }
                        if($scope.editModel3.startToTimeShow==0){
                            if($scope.editModel3.request.startToTime ==null
                                || $scope.editModel3.request.startToTime ==""){
                                $scope.editForm3.gStartToTime.$dirty=true;
                                $scope.editForm3.gStartToTime.$invalid=true;
                                return true;
                            }else{
                                $scope.editForm3.gStartToTime.$invalid=false;
                            }
                        }
                        return true;
                    }else{
                        if($scope.editModel3.startToTimeShow==0){
                            if($scope.editModel3.request.startToTime ==null
                                || $scope.editModel3.request.startToTime ==""){
                                $scope.editForm3.gStartToTime.$dirty=true;
                                $scope.editForm3.gStartToTime.$invalid=true;
                                return true;
                            }else{
                                $scope.editForm3.gStartToTime.$invalid=false;
                            }
                        }
                        if($scope.editModel3.request.startDate>$scope.editModel3.request.endDate){
                            $scope.editForm3.endDate.$invalid=true;
                            return true;
                        }
                        if($scope.editModel3.request.startDate < $scope.editModel3.request.endDate){
                            if($scope.editModel3.startToTimeShow==0){
                                if($scope.editModel3.request.startToTime == ""
                                    || $scope.editModel3.request.startToTime ==null){
                                    $rootScope.alertWarning("未填写，结束时间，请确认。");
                                    $scope.editForm3.gStartToTime.$dirty=true;
                                    $scope.editForm3.gStartToTime.$invalid=true;
                                    return true;
                                }
                                if($scope.editModel3.request.startToTime <= $scope.editModel3.request.startTime){
                                    $rootScope.alertWarning("结束时间不能小于开始时间。");
                                    $scope.editForm3.gStartToTime.$dirty=true;
                                    $scope.editForm3.gStartToTime.$invalid=true;
                                    return true;
                                }
                                $scope.editForm3.gStartToTime.$invalid=false;
                            }
                        }
                        if($scope.editModel3.request.hours<=0){
                            $rootScope.alertWarning("外出时长不能为0小时，请确认！");
                            $scope.editForm3.gEndTime.$invalid=true;
                            return true;
                        }
                        if($scope.editModel3.request.hours<60){
                            $rootScope.alertWarning("外出低于一小时不允许申请。");
                            return true;
                        }
                        return false;
                    }
                };

                $scope.viewButtonModel.saveDate = function(){
                    $scope.viewModel.isLoading = true;
                    if($scope.editModel3.type){
                        $request.saveRequest($scope.editModel3.request,
                            function(data){
                                $scope.viewButtonModel.unLoad();
                                $scope.viewModel.bindData();
                                $rootScope.alertInfo("新增成功。");
                                $scope.viewModel.isLoading = false;
                            },function(error) {
                                $rootScope.alertError(error.fault.message);
                                $scope.viewModel.isLoading = false;
                            });
                    }else{
                        $request.updateRequest($scope.editModel3.request,
                            function(data){
                                $scope.viewButtonModel.unLoad();
                                $scope.viewModel.bindData();
                                $rootScope.alertInfo("修改成功。");
                                $scope.viewModel.isLoading = false;
                            },function(error) {
                                $rootScope.alertError(error.fault.message);
                                $scope.viewModel.isLoading = false;
                            });
                    }
                };

                //保存
                $scope.viewButtonModel.save3 = function(){
                    $scope.editModel3.request.approvalState=0;
                    if($scope.viewButtonModel.requiredForm()){
                        return;
                    }
                    $rootScope.alertConfirm("确定保存吗？",function() {
                        $scope.viewButtonModel.saveDate();
                    });
                };

                //提交
                $scope.viewButtonModel.saveSubmit3 = function(){
                    $scope.editModel3.request.approvalState=1;
                    if($scope.viewButtonModel.requiredForm()){
                        return;
                    }
                    $rootScope.alertConfirm("确定保存并提交吗？",function() {
                        $scope.viewButtonModel.saveDate();
                    });
                };
			}
        };
        
		$scope.viewModel.dirty=function(type){
			//验证不能为空
			if ( type == '1' ) {
                $scope.editForm1.startDate.$dirty=false;
                $scope.editForm1.wStartTime.$dirty=false;
                $scope.editForm1.endDate.$dirty=false;
                $scope.editForm1.wEndTime.$dirty=false;
                $scope.editForm1.description.$dirty=false;
			} else if ( type == '0' ){
                $scope.editForm0.startDate.$dirty=false;
                $scope.editForm0.endDate.$dirty=false;
                $scope.editForm0.requestType.$dirty=false;
                $scope.editForm0.description.$dirty=false;
                $scope.editForm0.vStartTime.$dirty=false;
                $scope.editForm0.vEndTime.$dirty=false;
                $scope.editForm0.marryDate.$dirty=false;
                $scope.editForm0.timeTnterval.$dirty=false;
			} else if ( type == '2' ) {
                $scope.editForm2.startDate.$dirty=false;
                $scope.editForm2.bStartTime.$dirty=false;
                $scope.editForm2.endDate.$dirty=false;
                $scope.editForm2.bEndTime.$dirty=false;
                $scope.editForm2.description.$dirty=false;
			} else if ( type == '3' ) {
                $scope.editForm3.startDate.$dirty=false;
                $scope.editForm3.gStartTime.$dirty=false;
                $scope.editForm3.endDate.$dirty=false;
                $scope.editForm3.gEndTime.$dirty=false;
                $scope.editForm3.description.$dirty=false;
                $scope.editForm3.roleId.$dirty=false;
			}
		};
		
		//撤回补签
        $scope.viewRetroactiveCancelModel={};
        $scope.viewRetroactiveCancelModel.show=false;
        $scope.viewRetroactiveCancelModel.dataList=[];
		
		//加载一键补签页面
		$scope.viewRetroactiveCancelModel.load=function(){
			var attendance=null;
        	var checkboxlength=0;
        	//处理选择框
        	for(var i=0;i<$scope.viewModel.dataList.length;i++){
        		if($scope.viewModel.dataList[i].checkbox){
        			attendance=angular.copy($scope.viewModel.dataList[i]);
        			checkboxlength++;
        		}
        	}
        	if(checkboxlength>1){
        		$rootScope.alertWarning("请选择一条考勤信息操作！");
        		return;
        	}else if(checkboxlength==0){
        		$rootScope.alertWarning("请选择考勤信息！");
        		return;
        	}
            $scope.viewModel.isLoading = true;
            
            var data={};
            data.attendanceDate=attendance.attendanceDate;
        	Service.getRetroactives(data,
                    function(data){
        				$scope.viewRetroactiveCancelModel.dataList=data;
        				for(var i=0;i<$scope.viewRetroactiveCancelModel.dataList.length;i++){
        					$scope.viewRetroactiveCancelModel.dataList[i].checkbox=false;
        				}
                        $scope.viewModel.isLoading = false;
                    },function(error) {
                        $rootScope.alertError(error.fault.message);
                        $scope.viewModel.isLoading = false;
                    });
			$scope.viewRetroactiveCancelModel.show=true;
		};
		
		$scope.viewRetroactiveCancelModel.unLoad=function(){
			$scope.viewRetroactiveCancelModel.show=false;
		};
		
		
		//保存
        $scope.viewRetroactiveCancelModel.save=function(){
        	var attendanceList=[];
        	$scope.viewRetroactiveCancelModel.attendance={};
        	$scope.viewRetroactiveCancelModel.attendance.attendanceList=[];
        	//处理选择框
        	for(var i=0;i<$scope.viewRetroactiveCancelModel.dataList.length;i++){
        		if($scope.viewRetroactiveCancelModel.dataList[i].checkbox){
        			var attendance={};
        			attendance.attendanceId=$scope.viewRetroactiveCancelModel.dataList[i].attendanceId;
        			if($scope.viewRetroactiveCancelModel.dataList[i].startTime!=null){
        				attendance.type=0;
        			}else if($scope.viewRetroactiveCancelModel.dataList[i].endTime!=null){
        				attendance.type=1;
        			}
        			attendanceList.push(attendance);
        		}
        	}
        	if(attendanceList.length<=0){
        		$rootScope.alertWarning("请选择补签信息！");
        		return;
        	}
        
        	$scope.viewRetroactiveCancelModel.attendance.attendanceList=angular.copy(attendanceList);
        	
        	$rootScope.alertConfirm("确定撤回补签吗？",function() {
				$scope.viewModel.isLoading = true;
				Service.retractAttednance($scope.viewRetroactiveCancelModel.attendance,
				function(data){	
					$scope.viewRetroactiveCancelModel.unLoad();
					$scope.viewModel.bindData();
					$rootScope.alertInfo("撤回补签成功。");
					$scope.viewModel.isLoading = false;
				},function(error) {
					$rootScope.alertError(error.fault.message);
					$scope.viewModel.isLoading = false;
				});
			});
		};
} ]);